Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Inserting a Document's Path.

Inserting a Document's Path

Written by Allen Wyatt (last updated November 28, 2023)
This tip applies to Word 2007, 2010, 2013, and 2016


3

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:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (394) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Inserting a Document's Path.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Returning Zero When a Referenced Cell is Blank

Reference a cell in a macro, and if that cell is blank Excel normally equates that to a zero value. What if you don't ...

Discover More

Dragging to Clear Cells

If you want to get rid of the contents of a range of cells, a quick way to do it is with the Fill handle. Yes, you can ...

Discover More

Inserting a Bullet

Need to place a bullet in the middle of a sentence? There are a couple of easy ways you can do this, as described in this ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Inserting a Dynamic Word Count in Your Document

Need to know how many words are in your document? You can use the NumWords field to add that statistic, dynamically, to ...

Discover More

Searching for a Specific Field

Fields can be a great boon to document development, as they allow you to insert different types of dynamic information in ...

Discover More

Inserting a Document's Size

Want to insert the size of your document directly into the document body? You can do so by using one of the dynamic ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 0?

2021-09-15 20:07:36

George Noonan

I converted over to a new computer. When I did this, I made a mistake. I added the word "Biz" into the path of my new computer. Now my old documents are not working because the path is different on the new computer vs. the old one.

Any ideas how I can fix this?


2017-12-04 13:07:32

Downtown MKE

Does this tip work for a document number situation? I work in Law and our document management system generates a document number, versus a file path name.


2017-12-02 09:25:16

MIchael Armstrong

When I open a Word document, the filename displays in the top margin of the page -- e.g., "history.docx - Word". Is there a way to cause the full pathname to appear there?


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.