VBA Word 03:  Hiding File Extension when Filename Field is inserted into document

Posted on 2005-04-13
Last Modified: 2012-06-21
Hi There,

Basically, when we insert the filename field into a word doc it includes the file extension (.doc), which we don't want.  (I know that we can set the "hide known file extensions" option in Explorer, but then that's such a useful tool, we'd hate to lose it.)

Is there anyway to manipulate the filename field with vba coding to NOT show the .doc extension?  

I thought about converting the field to text and then deleting the .doc, but then it obviously won't update the next time we do a saveas.

Any ideas?  Or am I dreaming out of the Microsoft Scope?

Thanks, JTG

Question by:jtaylerg
    LVL 13

    Assisted Solution

    This will do it:

    You can test by typing this into an immediate window and then hitting enter:
    ? left(activedocument.Name,(len(activedocument.Name)-4))

    LVL 76

    Accepted Solution

    The simplest way would be to place a bookmark where you need the name and to put this code in the ThisDocument module

    Private Sub Document_Open()
        Dim rng As Range
        Dim bmk As Bookmark
        Set rng = ActiveDocument.Bookmarks("bmkDocTitle").Range
        rng.Text = Split(ActiveDocument.Name, ".")(0)
        ActiveDocument.Bookmarks.Add "bmkDocTitle", rng
    End Sub

    Author Comment

    Hi TommyTupa & GrahamSkan,

    Sorry about not getting back sooner -- taxes -- ugh.

    Both of your suggestions work great, but I was hoping to find a way to manipulate the field called FILENAME.

    Do you know if that can be done?  That way, we can have the filename updated when the documents are copied.

    Thanks for the help.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
    Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
    This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
    This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now