Solved

How to use the current folder using VBA

Posted on 2009-05-12
4
678 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:daleoran
  • 2
4 Comments
 
LVL 9

Expert Comment

by:drequinox
ID: 24365972
try
currentproject.path , this will get files from the location where the file is running from everytime..



0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 24366530
Did you try using

ThisDocument.Path

in the macro. This should give you the current folder name with full path.
0
 
LVL 10

Author Comment

by:daleoran
ID: 24369408
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

0
 
LVL 10

Accepted Solution

by:
daleoran earned 0 total points
ID: 24594384
Answer was

ActiveDocument.path
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question