Seems a reasonable approach. What's the question?
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
> Seems a reasonable approach. What's the question?
>
[quoted text clipped - 16 lines]
> >> >
> >> > thanks in advance.
Jezebel - 23 Nov 2006 11:29 GMT
Dim pRange As Word.Range
Set pRange = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
pRange = "Filename: "
pRange.Collapse Direction:=wdCollapseEnd
pRange.Fields.Add Range:=pRange, Type:=wdFieldFileName, Text:="\p"
> Ultimately, I want {FileName \p} to appear after the 'File Name:-' string
> like so
[quoted text clipped - 58 lines]
>> >> >
>> >> > thanks in advance.
hb - 23 Nov 2006 12:33 GMT
Thanks for that but there is one slight problem. There is a table with
various information (ie. VAT no. etc) in the footer of the document and this
appears to remove it.
> Dim pRange As Word.Range
>
[quoted text clipped - 65 lines]
> >> >> >
> >> >> > thanks in advance.
Jezebel - 23 Nov 2006 20:04 GMT
Sheesh, you really need spoon-feeding, don't you? Try the InsertAfter
method.
> Thanks for that but there is one slight problem. There is a table with
> various information (ie. VAT no. etc) in the footer of the document and
[quoted text clipped - 76 lines]
>> >> >> >
>> >> >> > thanks in advance.