#1
|
|||
|
|||
How to refer to a file in the same directory
I have a document where a user opens the document and it runs a macro.
I want to have a tick box so that if a user clicks 'yes' it adds the text from a Word file which is stored in the same directory as the 'macro' base file is stored. How do I refer to this? I know to use the file name but does Word / VBA assume it will be in the same directory? If not how do I tell it? |
#2
|
||||
|
||||
You will need to be explicit in providing the actual path. In VBA you could use
Code:
ThisDocument.Path & Application.PathSeparator & "My Doc.docx" 'or ActiveDocument.Path & Application.PathSeparator & "My Doc.docx" ActiveDocument is the document which is currently active (on top) Application.PathSeparator is a tortuous way to write \ but we use it in case the code is being used on a Mac, in which case it becomes ":" because that is how a Mac separates folders
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Strip out numbers from file names in a directory. | JustJim | Word VBA | 2 | 10-20-2021 06:40 PM |
Using Word VBA to change file names in a directory | sg11 | Word VBA | 4 | 03-22-2018 04:25 AM |
Changing file directory from a temp folder | dwirony | Word VBA | 6 | 12-13-2016 09:41 PM |
Replacing jpg file in each file of a directory | hklein | Word VBA | 4 | 10-14-2013 04:40 PM |
Auto-File Naming/ Default Directory Saves | sgill32 | Word | 2 | 11-06-2008 02:12 PM |