Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Inserting a Document's Path.
Written by Allen Wyatt (last updated August 5, 2023)
This tip applies to Word 97, 2000, 2002, and 2003
Brian knows he can insert, in his document, the FILENAME field with the /p switch; this inserts the path and filename under which the document is stored. He would like, however, to only insert the path without the actual filename.
There are two ways you can approach this problem. The first is to modify how you use the FILENAME field in your document. When you insert the field, it should look similar to the following. (If you can't see the field code, place the insertion point within the field result and press Shift+F9.)
{ FILENAME \p }
What you want to do is change the field code so it looks like this:
{ FILENAME \p \* MERGEFORMAT }
Now, collapse the field by making sure the insertion point is within the code and pressing F9. The field results should still show the full path, along with the filename. Select the file name and then format it as hidden text. Even if the field is updated, the filename will remain as hidden text. As you learn in other WordTips, you can turn off the display of hidden text and you can cause hidden text to not be printed.
The second approach is to use a macro to insert just the information you need. This approach becomes necessary if you are using hidden text for other purposes. The following is an example of a macro that will insert the path:
Sub PathOnly() With ActiveDocument If Len(.Path) = 0 Then .Save Selection.TypeText .Path & "\" End With End Sub
To use the macro, just put the insertion point where you want the path to appear and run it. If the document has not been saved (the only time the path length will be 0), then the user is prompted to save it. Because the macro inserts the path that is current when the macro is run, if you later change where the document is stored, you'll need to delete the old path from the document text and then run the macro again.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (391) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Inserting a Document's Path.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Did you know that Word tries to keep track of who the author of a document is? This information can be easily added to ...
Discover MoreNeed to jump from one place in your document to another? One way to do this is through the user of the GotoButton field, ...
Discover MoreThe COMPARE field is rather esoteric, but it can be helpful when you need to compare two values using fields. The result ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments