Problem opening file from a macro


Posted by Lewis on November 12, 2001 7:24 AM

I am using the following to open another XL file
Workbooks.Open Filename:="Trainingdb1.xls"
The problem is that unless it is on my recent files list, I get an error 1004 "not found"
Can I get round this?

Posted by Barrie Davidson on November 12, 2001 7:30 AM

Is this file in your current path settings (I'm betting it's not). If you include the path in the file name, it won't matter what path you are currently in. For example, if the file resides in C:\Data and your current path (what you see when you select file open, for instance) is D:\Files, then you will get this error message.

Does this help you out?

BarrieBarrie Davidson

Posted by Lewis on November 12, 2001 7:41 AM

Both files are in the same folder so I don't think this is my problem

Lewis

Posted by Barrie Davidson on November 12, 2001 7:51 AM

That's not what I was saying. What is the full path and file name of the file you are opening (e.g., C:\Trainingdb1.xls)? When you select File|Open (in Excel, not via VBA), what is the path?

BarrieBarrie Davidson

Posted by Lewis on November 12, 2001 8:09 AM

The open file with the Macro is C:\My Documents\General\ISO bits\Training Update.xls
And the file it is trying to open
C:\My Documents\General\ISO bits\Trainingdb1.xls

What is the significance of the colon before the equals sign?

Lewis

Posted by Barrie Davidson on November 12, 2001 8:14 AM

The colon before the equals sign is the syntax Excel requires to pass on the variable.

You have not answered my other question - When you select File|Open from the main menu, what is the path name Excel is looking in (box labeled "Look in" when the File Open box opens up)?

BarrieBarrie Davidson

Posted by Lewis on November 12, 2001 8:21 AM

Both are in C:\My Documents\General\ISO bits

Lewis

Posted by Barrie Davidson on November 12, 2001 8:30 AM

Boy, this is tough doing this via the board. I'm not asking the location of the files. The problem you are having is because Excel's default location (for lack of a better term) is not currently set to "C:\My Documents\General\ISO bits\".

At any rate, change your code to read:

Workbooks.Open Filename:="C:\My Documents\General\ISO bits\Training Update.xls"

This eliminates the need for Excel to be in the specific directory in order for your macro to work.

I think this should solve your problem. If not, just let me know via this board.

Sincerely,
BarrieBarrie Davidson



Posted by Lewis on November 12, 2001 8:42 AM

That has fixed it
Thanks very much for your patient help!

Lewis