Link to home
Start Free TrialLog in
Avatar of daleoran
daleoranFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to use the current folder using VBA

I'm currently writing a small macro that when run will find key words in a document and insert a file at that location. The file to be inserted will always be in the same folder as the main document. So my question is how do I tell the macro to get the file in the same folder? The reasoning is that if I move the folder to another computer or location it will always find the file.

Hope this makes sense

Many thanks in advance.
Avatar of drequinox
drequinox

try
currentproject.path , this will get files from the location where the file is running from everytime..



Avatar of Shanmuga Sundaram D
Did you try using

ThisDocument.Path

in the macro. This should give you the current folder name with full path.
Avatar of daleoran

ASKER

Sorry can't seem to get them to work. I'm using this

Selection.InsertFile FileName:=Path & Count & ".txt"

where Path is either currentproject.path or ThisDocument.Path

ASKER CERTIFIED SOLUTION
Avatar of daleoran
daleoran
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial