FileName Field - File Extension

J

Jules

We use the FileName field for footers on our documents. Depending on whether
your Explorer/My Computer folder settings are set to show file extensions or
not seems to dictate whether the file extension shows on your Word document.
Is there any way that the footer can be set up using the FileName field
without showing the file extension even when you have Explorer/My Computer
set to show file extensions (maybe with a macro or autotext)?

thank you
 
M

macropod

Hi Jules,

No. The fielname field always includes the extension - the only option you have is whether to include the filepath.
 
G

Graham Mayor

You can insert the filename without the extension using a macro

Sub InsertfNameAndPath()
Dim pPathname As String
With ActiveDocument
If Len(.Path) = 0 Then
.Save
End If
If Right(.name, 1) = "x" Then
pPathname = Left$(.FullName, (Len(.FullName) - 5))
Else
pPathname = Left$(.FullName, (Len(.FullName) - 4))
End If
End With
Selection.TypeText pPathname
End Sub

http://www.gmayor.com/installing_macro.htm

The above will insert the path at the cursor. You could add code to insert
it in one or more of the document footer ranges, but to do so would require
some knowledge of how the footers are arranged and whether any of them
already contains text - and if so where in relation to that text do you want
to add the filename.

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

My web site www.gmayor.com

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

Jules

Thanks very much.

Graham Mayor said:
You can insert the filename without the extension using a macro

Sub InsertfNameAndPath()
Dim pPathname As String
With ActiveDocument
If Len(.Path) = 0 Then
.Save
End If
If Right(.name, 1) = "x" Then
pPathname = Left$(.FullName, (Len(.FullName) - 5))
Else
pPathname = Left$(.FullName, (Len(.FullName) - 4))
End If
End With
Selection.TypeText pPathname
End Sub

http://www.gmayor.com/installing_macro.htm

The above will insert the path at the cursor. You could add code to insert
it in one or more of the document footer ranges, but to do so would require
some knowledge of how the footers are arranged and whether any of them
already contains text - and if so where in relation to that text do you want
to add the filename.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

macropod

Hi Graham,

How about:
Sub InsertfNameAndPath()
With ActiveDocument
If Len(.Path) = 0 Then .Save
Selection.TypeText Split(.FullName, ".")(0)
End With
End Sub
 
G

Graham Mayor

There's more than one way to skin a cat, however I don't like this method
when used with filenames as there is a growing practice of using the full
stop (period) character in filenames other than before the extension.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

If I understand your documentation, using the Wordbasic command there is no
switch to include the path and the filename without the extension, so while
this overcomes one issue, it introduces another. Using .name or .fullname in
the string makes no difference, nor can you add the numbers to make a
combination, so you would have to use

WordBasic.FileNameInfo$(ActiveDocument.FullName, 5) & _
WordBasic.FileNameInfo$(ActiveDocument.FullName, 4)

which frankly is just as clumsy as what I had originally - interesting
technique though. Thanks for reminding me of that page :)

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

macropod

OK Graham,

How about:
Sub InsertfNameAndPath()
With ActiveDocument
If Len(.Path) = 0 Then .Save
Selection.TypeText Left(.FullName, InStrRev(.FullName, ".") - 1)
End With
End Sub
 
G

Graham Mayor

That works :)
OK Graham,

How about:
Sub InsertfNameAndPath()
With ActiveDocument
If Len(.Path) = 0 Then .Save
Selection.TypeText Left(.FullName, InStrRev(.FullName, ".") - 1)
End With
End Sub
 

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