Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Document Opening in VBA 3

Status
Not open for further replies.

DLG0311

Technical User
Jan 6, 2005
13
GB
The following command line steadfastly refuses to open the required document which is stored in the same directory as the document containing the macro.

Documents.Open FileName:="Invoice Request Database.doc"

Can someone explain why, please.

Could it be that this is because neither document is in the default "My Documents" or equivalent?
 
Hi DLG0311,

You're more or less right in what you suggest. The directory containing the document containing the macro is irrelevant.

Unqualified file names will be searched for in the default Documents Folder. The stored default is available and changeable via Tools > Options > File Locations (the built-in default for this is My Documents). At any point in a Word session, the actual working value for this directory name depends on previous activity and is not necessarily the same as that shown in Tools > Options.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Ok, thanks very much. The documents are to be circulated throughout the Council and each user will (probably) have them in different places (alhtought both will remain together). How do I get the macro to look in the directory where the two documents are rather than default?

Darryll Le Geyt
 
Well, more correctly, as this is Word, ..

ThisDocument.Path

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
As in:
Code:
Documents.Open FileName:=ActiveDocument.Path & Application.PathSeparator & "Invoice Request Database.doc"

Although as Tony pointed out you can also use ThisDocument.Path - which in fact would probably be better. You could also use "\" as part of the file name string. I tend to use PathSeparator.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top