Insert Filename Field

J

Johann Swart

Win XP Pro Version 5.1 SP2
Word 2002 SP3

I would like to insert a field in my Word document containing the electronic
name of the file, i.e. Insert Field, Document Information, File Name, Upper
Case.
I would prefer NOT to have the "*.doc" (dot doc) file extension.
Is there some way one can achieve this?
 
G

Graham Mayor

Not with a field - but you can insert the filename without the extension at
the cursor eg

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

Sub InsertFnameOnly()
With ActiveDocument
If Len(.Path) = 0 Then .Save
Selection.TypeText UCase(Left(.name, InStrRev(.name, ".") - 1))
End With
End Sub


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


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

Graham Mayor

On further reflection you could assign the filename to a docvariable then
insert a docvariable field

Dim oVars As Variables
Dim vVar As Variant
Dim bExists As Boolean
Dim Order As Integer
Set oVars = ActiveDocument.Variables
bExists = False
For Each vVar In oVars
If vVar.name = "vFname" Then
bExists = True
Exit For
End If
Next vVar
With ActiveDocument
If Len(.Path) = 0 Then .Save
If bExists = False Then
oVars("vFname").Value = _
UCase(Left(.name, InStrRev(.name, ".") - 1))
End If
For i = 1 To .Fields.Count
If .Fields(i).Type = wdFieldDocVariable Then
.Fields(i).Update
End If
Next i
End With

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


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

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