Solved

How to use the current folder using VBA

Posted on 2009-05-12
4
674 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Answer was

ActiveDocument.path
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now