Joanne M. Orzech
asked on
Filename and path footer on every page of every section of document in Word 2000
I need a filename and path footer on every page of every section in documents in Word 2000. I've got the code I need from Rajesh (thanks!) here:
https://www.experts-exchange.com/questions/20794791/How-to-use-VBA-to-add-a-textbox-to-each-available-header-in-a-document.html#9736024
But I can't figure out if there's a different first page footer how to make it work.
Here's what I have so far:
Sub FooterEveryPage()
If ActiveWindow.View.SplitSpe cial <> wdPaneNone Then
ActiveWindow.Panes(2).Clos e
End If
If ActiveWindow.ActivePane.Vi ew.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.Vi ew.Type = wdPrintView
End If
ActiveWindow.ActivePane.Vi ew.SeekVie w = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.Vi ew.SeekVie w = wdSeekCurrentPageFooter
sCount = ActiveDocument.Sections.Co unt
For sec = 1 To sCount
With ActiveDocument.Sections(se c)
If ActiveDocument.Sections(se c).Applica tion.Selec tion. _
HeaderFooter.LinkToPreviou s = False Then
InsertFooter
End If
End With
If sec < sCount Then ActiveWindow.ActivePane.Vi ew.NextHea derFooter
Next sec
ActiveWindow.ActivePane.Vi ew.SeekVie w = wdSeekMainDocument
End Sub
Sub InsertFooter()
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.ParagraphFormat. Alignment = wdAlignParagraphLeft
Selection.Font.Size = 8
NormalTemplate.AutoTextEnt ries("File name and path").Insert Where:= _
Selection.Range
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="M/d/yyyy h:mm am/pm", _
InsertAsField:=True, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
End Sub
Many thanks!
https://www.experts-exchange.com/questions/20794791/How-to-use-VBA-to-add-a-textbox-to-each-available-header-in-a-document.html#9736024
But I can't figure out if there's a different first page footer how to make it work.
Here's what I have so far:
Sub FooterEveryPage()
If ActiveWindow.View.SplitSpe
ActiveWindow.Panes(2).Clos
End If
If ActiveWindow.ActivePane.Vi
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.Vi
End If
ActiveWindow.ActivePane.Vi
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.Vi
sCount = ActiveDocument.Sections.Co
For sec = 1 To sCount
With ActiveDocument.Sections(se
If ActiveDocument.Sections(se
HeaderFooter.LinkToPreviou
InsertFooter
End If
End With
If sec < sCount Then ActiveWindow.ActivePane.Vi
Next sec
ActiveWindow.ActivePane.Vi
End Sub
Sub InsertFooter()
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.ParagraphFormat.
Selection.Font.Size = 8
NormalTemplate.AutoTextEnt
Selection.Range
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="M/d/yyyy h:mm am/pm", _
InsertAsField:=True, DateLanguage:=wdEnglishUS,
wdCalendarWestern, InsertAsFullWidth:=False
End Sub
Many thanks!
ASKER
Awesome Dragontooth! It works great except it puts four footers on each page....
ASKER
If it's any clue - my document has four sections. If I add another section, it adds five footers....clear this up and I'll be a very happy camper :)
Thanks so much!
Thanks so much!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are awesome!!!! Excellent work Dragontooth. Increased points for ya ;)
Thanks again.
Joanne
Thanks again.
Joanne
Thanks for the Points and the Grade!!
dragontooth
dragontooth
Hmm... maybe I'm missing something here but why not just use the built-in filename field with the \p option in the page footers?
I use {FILENAME \p} all the time in Word XP. (You can get it from the Insert Field... dialog or type in "filename \p" (no quotes), select it and press Ctrl-F9 to change it to a field code.)
Eric
I use {FILENAME \p} all the time in Word XP. (You can get it from the Insert Field... dialog or type in "filename \p" (no quotes), select it and press Ctrl-F9 to change it to a field code.)
Eric
ASKER
But page footers change from section to section
@JOrzech, page footers change on each page that is why the rewrite occured <If I add another section, it adds five footers> There is also a different first page footer, odd/even page footer and last but not least just a plain old footer on each page either not like the others/or like the others.
@EricFletcher, Word 200 does not allow {FILENAME \p} to be type as you suggested (what happens is the {FILENAME \p} stays that way). The insert field is allowed and it works real good. Word 2000 is not as flexible as Word XP I guess.
dragontooth
@EricFletcher, Word 200 does not allow {FILENAME \p} to be type as you suggested (what happens is the {FILENAME \p} stays that way). The insert field is allowed and it works real good. Word 2000 is not as flexible as Word XP I guess.
dragontooth
Dragontooth: It should work. I also have Word 97 on an old laptop and it works fine there. If you see the field braces after you pressed Ctrl-F9, the definition took -- but you probably didn't toggle the view with Alt-F9 to see the results. (This has been an annoyance in Word for ages: the excuse I was given is that people need to see that they've added a field code; otherwise they might get confused if something else just suddenly appeared.)
As with many fields, you may need to cause this field to be "recalculated" by pressing F9 or switching out of page view and back. Also, note that if you haven't saved the file yet, the path will not show.
Eric
As with many fields, you may need to cause this field to be "recalculated" by pressing F9 or switching out of page view and back. Also, note that if you haven't saved the file yet, the path will not show.
Eric
Ah the Alt-F9, didn't know that Thanks. I would also like to thank you for your comments the more I learn the more I find I don't know!
Follow the link below in appreciation of the time, tip, and your very productive comments.
https://www.experts-exchange.com/questions/20827584/points-for-EricFletcher.html
dragontooth
Follow the link below in appreciation of the time, tip, and your very productive comments.
https://www.experts-exchange.com/questions/20827584/points-for-EricFletcher.html
dragontooth
ASKER
You guys are awesome...but I work with Word 2000 at work.... :(
I know about he alt f9 and all that other.... mebbe I'm the one missing something... tell me, is it true?
I know about he alt f9 and all that other.... mebbe I'm the one missing something... tell me, is it true?
IMHO no. I didn't know about the alt-F9, but not knowing exactly what is going on, I will not tell someone to update their fields, the reason is some fields are filled though code, Alt-F9 would reset these fields and the information would be gone. Another thing is you may be printing out the doc before saving in which case the field would not be updated until save if I understand correctly. So from an end user's standpoint the {FILENAME \p} would work just fine/the best, IMHO from a coders viewpoint there are other options that would be best depending on the requirements. ex. The filename in the footer is where the original is stored but the current one is actually someplace else.
dragontooth
dragontooth
I changed the above code to pick up all of the footers. I tested on a blank doc with a different first page header, 3 pages. If there is more that you need let me know.
Sub FooterEveryPage()
If ActiveWindow.View.SplitSpe
ActiveWindow.Panes(2).Clos
End If
If ActiveWindow.ActivePane.Vi
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.Vi
End If
ActiveWindow.ActivePane.Vi
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.Vi
' start changes ******
While Err.Number = 0 '< added this for an exit key
sCount = ActiveDocument.Sections.Co
For sec = 1 To sCount '< in my testing this remains 1 maybe yours doesn't I used a blank doc
With ActiveDocument.Sections
If ActiveDocument.Sections.Ap
HeaderFooter.LinkToPreviou
InsertFooter
End If
End With
Next sec
On Error Resume Next '< resume next on error cause it throws an error when no more different footers
ActiveWindow.ActivePane.Vi
Wend
Err.Clear '< there is an error so exit clear error get through
On Error GoTo 0
' end changes ****** I commented out the trouble are and left alone - backup place to start
'sCount = ActiveDocument.Sections.Co
'For sec = 1 To sCount
' With ActiveDocument.Sections(se
' If ActiveDocument.Sections(se
' HeaderFooter.LinkToPreviou
' InsertFooter
' End If
' End With
' If sec < sCount Then ActiveWindow.ActivePane.Vi
'Next sec
ActiveWindow.ActivePane.Vi
End Sub
Sub InsertFooter()
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.ParagraphFormat.
Selection.Font.Size = 8
NormalTemplate.AutoTextEnt
Selection.Range
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="M/d/yyyy h:mm am/pm", _
InsertAsField:=True, DateLanguage:=wdEnglishUS,
wdCalendarWestern, InsertAsFullWidth:=False
End Sub
HTH
dragontooth