Field Codes: Filename

J

John X. Perez

How do you limit the characters to be displayed using the FILENAME field
code?

I use a long identifying filename like "Doc 1234 This is the Smith Document
version 3.doc"; however, at the end of the file I just want to note the
certain information from the filename like "Doc 1234 version 3". FILENAME
puts the whole name, is there a way to specific which characters to use?

Just deleting them doesn't work because as soon as you update with F9 it
resets to the whole long name....

Help!

Tks/
 
G

Graham Mayor

Not easily. You could extract parts of the filename using vba eg the
following will extract the required parts of the particular quoted filename,
but how useful it would be would depend on how strictly you save your files
in that format and my guess is that for real examples it will not work
without much modification.

Sub InsertFName()
Dim fname, fname2 As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname = Selection.Document.Name
fname2 = Left(fname, 9) & Mid(fname, 37, 9)
Selection.TypeText fname2
End Sub

However, a simpler solution presents itself. Use the basic macro (below) to
insert the filename as text, then delete the bits you don't want from it,
and as it is not a field, it will not update.

Sub InsertFName()
Dim fname As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname = Selection.Document.Name
Selection.TypeText fname
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John X. Perez

I think this would work well...I just have to change my format to read "Doc
1234 version 9 This is the Smith--.doc" then I would always use the first
(in this case) 18 characters! But, how do I stick what you wrote in so that
it always works on every document. Do I just copy-paste it somewhere?
Sorry, I'm not terribly familiar with VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top