Removing the file extension from an inserted field/filename

R

Rick

Is there a simple way to remove the file extension from an inserted field/filename (without changing folder preferences in Windows to not display extensions for known file types)?

If not simple, does anyone already have the required VBA code to do this?

Regards
 
G

Graham Mayor

Whether or not the extension is displayed it is always part of the filename.
The extension is the initial method by which files are identified by
Windows. Why would you want to remove it from a field?

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Rick

I use the filename within a printed document and do not want to display the
fact that it is a word document. The .doc would thus display.

Any suggestions on how this can be acheived?

Regards
 
G

Graham Mayor

In that case use a macro to insert the filename without the extension -

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

will insert the path and filename
change the line fname=
to
fname = Selection.Document.Name
if you want to omit the path


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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