• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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

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




0
jtaylerg
Asked:
jtaylerg
2 Solutions
 
TommyTupaCommented:
This will do it:
left(activedocument.Name,(len(activedocument.Name)-4))

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

0
 
GrahamSkanCommented:
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
0
 
jtaylergAuthor Commented:
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.

JTG
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now