Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileName Field - File Extension

453 views
Skip to first unread message

Jules

unread,
May 19, 2009, 7:28:22 PM5/19/09
to
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

macropod

unread,
May 19, 2009, 8:35:24 PM5/19/09
to
Hi Jules,

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

--
Cheers
macropod
[Microsoft MVP - Word]


"Jules" <Ju...@discussions.microsoft.com> wrote in message news:4E89B5AB-5E22-4B2D...@microsoft.com...

Graham Mayor

unread,
May 20, 2009, 12:55:34 AM5/20/09
to
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
Word MVP web site http://word.mvps.org

Jules

unread,
May 20, 2009, 8:54:01 PM5/20/09
to
Thanks very much.

macropod

unread,
May 20, 2009, 11:58:42 PM5/20/09
to
Hi Graham,

How about:
Sub InsertfNameAndPath()


With ActiveDocument
If Len(.Path) = 0 Then .Save

Selection.TypeText Split(.FullName, ".")(0)
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message news:enbjycQ2...@TK2MSFTNGP06.phx.gbl...

Graham Mayor

unread,
May 21, 2009, 10:06:40 AM5/21/09
to
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
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


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

Jay Freedman

unread,
May 21, 2009, 11:23:57 AM5/21/09
to
Here's another way (courtesy of
http://word.mvps.org/FAQs/MacrosVBA/WordBasicCommands.htm):

WordBasic.FileNameInfo$(ActiveDocument.FullName, 4)

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Graham Mayor wrote:
> 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

unread,
May 22, 2009, 12:49:26 AM5/22/09
to
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
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Jay Freedman wrote:
> Here's another way (courtesy of
> http://word.mvps.org/FAQs/MacrosVBA/WordBasicCommands.htm):
>
> WordBasic.FileNameInfo$(ActiveDocument.FullName, 4)
>
>

macropod

unread,
May 22, 2009, 3:44:11 AM5/22/09
to
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

--
Cheers
macropod
[Microsoft MVP - Word]


"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message news:OUHwX1h2...@TK2MSFTNGP04.phx.gbl...

Graham Mayor

unread,
May 22, 2009, 4:16:11 AM5/22/09
to
That works :)

macropod wrote:
> 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
>
>

0 new messages