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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA: Why a macro reads a file from 2 different directories

Status
Not open for further replies.

sharon3874

Programmer
Oct 27, 2006
24
US
I am new in VBA. I am sorry in advance if my question doesn't make sense.

I have a word document and there is a button which trigger a macro. in the macro, I want to get some info from reading another doc.

the name of the file is like "additional_links.doc", since I didn't specify the path, so I expected that the macro should read the doc from the current directory. Here is what confused me, sometimes the macro read the file from the current directory, sometimes it read from another directory(I suspect the directory was set somewhere).

It really bothers me that it is not consistent. It read from these 2 directories back and forth, and I couldn't see any pattern of that.

Maybe it does not relate to word VBA, but has anyone have this problem before?

Thanks.
 
It would help if you posted the code of the macro.

It sounds like something else has changed the current directory.

A simple solution would be to in fact include the full path of the file you wish to open. It is almost always better to be explicit about things anyway.

Gerry
My paintings and sculpture
 
It sounds very much like the macro sets the directory somewhere else. It is therefore opening the file correctly then when opening again, it has set the directory to something else.

Just prior to opening the file, I would specify the location therefore it is unlikely to get confused.

Thanks

Adam Blackwell
Information Analyst
 
Thank you all for your quick responses.

I will deliver the doc to my users. I was just thinking that a relative path may be more flexible.
 
And what about ActiveDocument.Path & "\additional_links.doc" ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,
Thank you very much!!!

I think it works. I really appreciat your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top