opening a workbook in the current directory

R

Richard

I'm trying to determine whether or not this can be done using VBA:

Using Windows Explorer, say, I double-click to open an Excel file
located in a directory other than the default Excel directory. In this
workbook is VBA code that attempts to open another workbook located in
the same directory:

Workbooks.Open "XYZ.xls"

The operation fails, apparently because it's looking in the default
Excel directory. Is there a way to specify that the program look in the
current, working directory?

Rich
 
W

William

Richard

Try....

Workbooks.Open ThisWorkBook.Path & "\XYZ.xls"

--
XL2002
Regards

William
(e-mail address removed)

| I'm trying to determine whether or not this can be done using VBA:
|
| Using Windows Explorer, say, I double-click to open an Excel file
| located in a directory other than the default Excel directory. In this
| workbook is VBA code that attempts to open another workbook located in
| the same directory:
|
| Workbooks.Open "XYZ.xls"
|
| The operation fails, apparently because it's looking in the default
| Excel directory. Is there a way to specify that the program look in the
| current, working directory?
|
| Rich
 
J

Jim Carlock

Try to set a path variable inside of a procedure.

strPath = ThisWorkbook.Path

That will set the path to the current workbook. I've used that
successfully, but be warned... I've tried to set a private form
wide variable to do this to use between different procedures
and the variable doesn't keep itself intact. I can't figure out
what the deal is with that, but I get around it by declaring
(Dim) the variable in every procedure I need it and force the
ThisWorkbook.Path into it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top