open a file

sloaner14

Registered User.
Local time
Today, 14:47
Joined
Apr 25, 2002
Messages
32
I need to know how to open a file(same name and location everytime) word or excel with the click of a button on my form. I have limited VB and have tried eveything that I can think of. Any help will be greatly appreciated.
 
You could put a hyperlink on your form and browse to find the file. Once this is setup it will open this file everytime the hyperlink is clicked. I think you can do this via code also.

Hay
 
This is going to be a learning experience for you, but it isn't that hard.

First things first: To open a file, you have to know the COM (component object model) structure for the application. The help files in the app itself will tell you that.

Second, opening Excel or Word from Access involves the creation of an Object variable (note caps because it is specifically a variable of type Object). The code involves

Set myObject = CreateObject("Word.Application")

(or, of course, Excel.Application...)

Now you can open a document. The way you do it depends on the app.

For word:

myObject.Documents.Open

Look up the .Open for Word in the Word Help files for objects.

For excel:

myObject.Workbooks.Open

Again, look up the .Open for Excel in the Excel Help files for objects.

The thing you do next depends on the app, and you weren't specific, so I won't be either.

Don't forget when exiting your code to do a myObject.Close. If you created a new file, precede that with a myObject.SaveAs so you won't lose your work. Look up both methods in the appropriate help files for the specific apps.

For what it is worth, I use this ability all of the time for data import and even sometimes for export. Works great once you get used to it.

But I would never have thought I could EVER get used to anything done inside a Bill Gates product. ;)
 
I'm not sure what I'm doing wrong, but I'm trying to implement the code above and I'm having no luck. I'm getting an error "Method or data member not found" and Workbooks is highlighted. I thought maybe it was the references, but I tried adding Microsoft Excel 8.0 Object Library to no avail. I double checked excel help and Workbooks.Open works from excel. Any ideas why I might be having trouble? My current coding follows:
Code:
Dim myObject As Application
Set myObject = CreateObject("Excel.Application")
myObject.[Color=Red]Workbooks[/Color].Open "Schedule " & Format(Week, "dd-mm-yy")
 
Okay, I'm closer; but I still need help. I found the following, which opens the file (I guess I had to declare it as Excel.Application):
Code:
Dim myObject As Excel.Application
Set myObject = CreateObject("Excel.Application")
myObject.Workbooks.Open "T:/IAT Schedule/Schedule " _
& Format(Week, "mm-dd-yy"), , False
myObject.Visible = True
myObject.Close
I'm still running into two problems. First, it keeps opening Read-Only. I tried setting that to false, but no luck. Second, I cannot get the object to close. Any help is appreciated.
________________________________

I'm sorry for wasting everyone's time. Apparently, I had an instance of the file opened invisibly somewhere and the format for close was just myObject.Workbooks.Close.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom