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.
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:
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.
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!
Many companies (and some individuals) use specific formats for naming their documents. If you want Word to recognize your ...
Discover MoreWhen you organize your hard drive, it is easy to go hog-wild with folders and subfolders. You need to know that how you ...
Discover MoreNeed to save a new document, from within a macro, to a specific file name? If you use the Record Macro capabilities of ...
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 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.
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