File Name Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a client that recently updated to Word 2003 and want me to update
their templates. Several of the templates have the file name field in the
footer. The client insists that before the upgrade the file name would not
show the extension, but now that I have done the upgrade it does. They want
me to make it so that when the file name show it does not show the file name
with the .doc extension. Is this possible and if so, how can I do this?

Thanks!
 
This is not something you can control from Word. The extension is not shown
if you've checked the 'Hide extensions for known file types' checkbox in
Windows Explorer > Tools > Folder options.
 
Jezebel, Thanks for the answer. I didn't think to look outside of Word.
Thank you again!
--
All help is greatly appreciated and I am more than willing to reciprocate
when I can.


Jezebel said:
This is not something you can control from Word. The extension is not shown
if you've checked the 'Hide extensions for known file types' checkbox in
Windows Explorer > Tools > Folder options.
 
Personally I would prefer to know what file extensions are being used. You
could insert the filename without the extension using a macro -

Sub InsertfNameAndPath()
Dim fname, fname2, pathname As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname = Selection.Document.FullName
fname2 = Selection.Document.Name
pathname = Left(fname, (Len(fname) - 4))
Selection.TypeText pathname
End Sub

Sub InsertFnameOnly()
Dim fname, fname2 As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname2 = Selection.Document.Name
fname = Left(fname2, (Len(fname2) - 4))
Selection.TypeText fname
End Sub
 
Dim fname, fname2, pathname As String

Graham, you should know better than this! :) unless you really *want* to
declare fname and fname2 as variants... (but even then, it's better to be
explicit)
 
I don't profess any particular expertise at vba. It did the job. Feel free
to improve upon it :)

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
It's probably the most common coding mistake. With

Dim A, B, C as string

the 'as string' applies only to C. A and B get the default declaration,
which is variant. Eg, equivalent to

Dim A as variant, B as variant, C as string

Best practice is to declare each variable on a line of its own, and to
specify the type explicitly even if it is variant.
 
Thanks for the clarification. Will you settle for:

Sub InsertfNameAndPath()
Dim fname As String
Dim fname2 As String
Dim pathname As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname = Selection.Document.FullName
fname2 = Selection.Document.Name
pathname = Left(fname, (Len(fname) - 4))
Selection.TypeText pathname
End Sub

Sub InsertFnameOnly()
Dim fname As String
Dim fname2 As String
If ActiveDocument.Saved = False Then ActiveDocument.Save
fname2 = Selection.Document.Name
fname = Left(fname2, (Len(fname2) - 4))
Selection.TypeText fname
End Sub

;)

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
OK, if you want 'best practice' coding ...


Sub InsertfNameAndPath()

Dim pPathname as String

With ActiveDocument
If not .Saved Then
.Save
End If

pPathname = Left$(.FullName, (Len(.FullName) - 4))
End With

Selection.TypeText pPathname

End Sub


Paraphrased from one of the coding standards ....

-- Declarations should have a prefix to show the variable scope (procedure,
module, or global)
-- Don't make comparisons explicitly with TRUE or FALSE. Doesn't actually
matter with FALSE, but "If x = TRUE then" is not the same as "If x then"
-- Don't write one-line if-statements. Nothing wrong with them per se, but
they tend to be a source of bugs when the code gets re-worked later.
-- Use the string version of functions like Left$(), Mid$() etc -- MUCH
faster than the variant equivalents.


cheers :)
 
Back
Top