Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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 File Name without an Extension.

Inserting a File Name without an Extension

Written by Allen Wyatt (last updated March 30, 2019)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


You can use the FILENAME field to insert the current document's file name in your document. The exact way you use this field is described in other issues of WordTips. You can use field switches to specify whether you want the field results to include the full path for the file, or not. One thing you cannot specify, however, is whether you want the results to exclude the file extension.

One way you can control this is by configuring Windows to either display or hide filename extensions. You do that within Windows by following the steps on this page:

http://windows.tips.net/T012372

This approach works great as long as the documents are being viewed on your system. If the document is opened on someone else's system, then the FILENAME field will display the file extension according to the configuration of Windows that they have set up; this may be a drawback.

Another way to insert the file name without the extension is to use a different field. For instance, you could use File Properties to save the filename by typing it in manually without the extension. You could then use the DOCPROPERTY field to recall that specific property and insert it in your document. Other WordTips describe how to create and use document properties.

If you need to insert a static copy of the document name quite often, the best way to do it is with a macro. Consider the following single-line macro:

Sub InsertFileName()
    Selection.InsertBefore Text:=Left(ActiveDocument.Name, _
      Len(ActiveDocument.Name) - 5)
End Sub

Run this macro, and the name of your document (without the file extension) is inserted before whatever is selected in your document. The macro examines the document name, and then strips the last five characters (the period and file extension) from the name.

This approach works well for four-character file extensions, such as DOCX. If your files have a different number of characters in the file extension, you'll need to either change the code to strip off the correct number of characters or change it to automatically recognize how many characters there are in the extension.

Using the macro approach is very easy, but it isn't dynamic. This means that if the document name is changed, then the text in the document still reflects the old document name, not the new one. The way around that is to simply run the macro again to insert the new document name at whatever point you want it to appear.

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 (8558) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Inserting a File Name without an Extension.

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

Removing Personal Information

As you create and work on your workbooks, Excel can include sensitive personal information with the data. If you want to ...

Discover More

Setting a Transparent Color for an Image

Want to "see through" an image you place on a worksheet? You can do so by using the steps in this tip.

Discover More

Saving Changes when Closing

If your macro closes workbooks, you'll want to make sure that it will save any changes you made to the workbook. Here's ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Using a Standard Format in a Suggested File Name

Many companies (and some individuals) use specific formats for naming their documents. If you want Word to recognize your ...

Discover More

Limits on Path Length in Word

When you organize your hard drive, it is easy to go hog-wild with folders and subfolders. You need to know that how you ...

Discover More

Saving in a Macro Using a Desired File Name

Need to save a new document, from within a macro, to a specific file name? If you use the Record Macro capabilities of ...

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 two more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.