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

Saving a Preview with Your Template

Templates provide a collection of styles and boilerplate for new documents. Selecting the right template by filename only ...

Discover More

Excluding a Specific Add-In at Startup

Got an add-in that you don't want loaded each time that Excel starts up? Here's a few ways that you can exclude it.

Discover More

Deleting Duplicate Text Values

Got a list of data from which you want to delete duplicates? There are a couple of techniques you can use to get rid of ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Use Filenames that Sort Properly

If you take some care when you name your document files, you'll find it much easier to manage those files at a later ...

Discover More

Saving Your Work Automatically

Word can be configured to save your work periodically; on any time schedule you desire. This tip explains this feature ...

Discover More

Listing Documents with Passwords

Do you need a list of documents that require a password or that require a particular password to open? Word doesn't ...

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 2 + 2?

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.