Skip to main content

Kutools for Office β€” One Suite. Five Tools. Get More Done.

How to insert file path and filename without extension in Word document?

Author Xiaoyang Last modified

Normally, we can insert the filename or file path and name in the Word document by using the Filename field function, but, this inserted filename including the file extension docx or doc. How could you insert the file name or file path and name without extension?

Insert file path and name or filename without extension by using VBA code

Recommended Productivity Tools for Word

Kutools for Word: Integrating AI πŸ€–, over 100 advanced features save 50% of your document handling time.Free Download

Office Tab: Introduces the browser-like tabs to Word (and other Office tools), simplifying multi-document navigation.Free Download


Insert file path and name or filename without extension by using VBA code

To insert the filename without extension in Word document, please apply the following VBA code:

1. Put the cursor to a place where you want to insert the file path and name without extension.

2. Then, hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. And then, click Insert > Module, copy and paste below code into the opened blank module.

VBA code: Insert file path and name without extension:

Sub InsertFileNameAndPath()
    Dim xPathName As String
    Dim xDotPos As Integer
    With Application.ActiveDocument
        If Len(.Path) = 0 Then .Save
        xDotPos = VBA.InStrRev(.FullName, ".")
        xPathName = VBA.Left(.FullName, xDotPos - 1)
    End With
    Application.Selection.TypeText xPathName
End Sub

4. Then press F5 key to run this code and the file path and name has been inserted into the document without extension, see screenshot:

The file path and name are inserted into the document without extension

Note: If you just want to insert the file name without extension into the document, you should apply this code:

VBA code: Insert file name only without extension:

Sub InsertFileNameOnly()
    Dim xPathName As String
    Dim xDotPos As Integer
    With Application.ActiveDocument
        If Len(.Path) = 0 Then .Save
        xDotPos = VBA.InStrRev(.Name, ".")
        xPathName = VBA.Left(.Name, xDotPos - 1)
    End With
    Application.Selection.TypeText xPathName
End Sub

Best Office Productivity Tools

Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!

πŸ€– Kutools AI Features: AI Assistant / Real-Time Assistant / Super Polish (Preserve Format) / Super Translate (Preserve Format) / AI Redaction / AI Proofread...

πŸ“˜ Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF...

✏ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...

🧹 Effortless Clean: Sweap away Extra Spaces / Section Breaks / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...

βž• Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Multiple Pictures / Discover more in the Insert group...

πŸ” Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...

⭐ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...

🌍 Supports 40+ Languages: Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Kutools and Kutools Plus tabs on the Word Ribbon
πŸ‘‰ Want to try these features? Download Kutools for Word now! πŸš€
 

✨ Kutools for Office – One Installation, Five Powerful Tools!

Includes Office Tab Pro Β· Kutools for Excel Β· Kutools for Outlook Β· Kutools for Word Β· Kutools for PowerPoint

πŸ“¦ Get all 5 tools in one suite | πŸ”— Seamless integration with Microsoft Office | ⚑ Save time and boost productivity instantly

Best Office Productivity Tools

Kutools for Word - 100+ Tools for Word