Ultimately, I want {FileName \p} to appear after the 'File Name:-' string
like so
File Name:-c:\test.doc
So, I want to modify this code, which just inserts the file name field in
the start of the footer, to find the 'File Name:-' string and insert the
field after it.
Sub PutFileNameOnLastPage()
' Are any documents open?
If Documents.Count = 0 Then Exit Sub
' Go to footer of document in the last section
' of the document.
Selection.EndKey Unit:=wdStory
If ActiveWindow.ActivePane.View.Type = wdNormalView Or _
ActiveWindow.ActivePane.View.Type = wdOutlineView Or _
ActiveWindow.ActivePane.View.Type = wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
' If the document already contains a filename, exit this routine.
For Each ao In Selection.HeaderFooter.Range.Fields
If ao.Type = wdFieldFileName Then
' Just exit
Exit Sub
End If
Next
' Add the Filename field.
ActiveWindow.View.ShowFieldCodes = True
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME \p "
Selection.HeaderFooter.Range.Fields.Update
End With
Regards
HB