Link to home
Start Free TrialLog in
Avatar of Joanne M. Orzech
Joanne M. OrzechFlag for United States of America

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.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
sCount = ActiveDocument.Sections.Count
For sec = 1 To sCount
With ActiveDocument.Sections(sec)
If ActiveDocument.Sections(sec).Application.Selection. _
HeaderFooter.LinkToPrevious = False Then
    InsertFooter
End If
End With
If sec < sCount Then ActiveWindow.ActivePane.View.NextHeaderFooter
Next sec
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

Sub InsertFooter()
    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    Selection.Font.Size = 8
    NormalTemplate.AutoTextEntries("Filename 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!
Avatar of Tommy Kinard
Tommy Kinard
Flag of United States of America image

Hi JOrzech,

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.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
            ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
' start changes ******
    While Err.Number = 0                                '< added this for an exit key
        sCount = ActiveDocument.Sections.Count
        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.Application.Selection. _
                HeaderFooter.LinkToPrevious = False Then
                    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.View.NextHeaderFooter
    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.Count
    'For sec = 1 To sCount
    '    With ActiveDocument.Sections(sec)
    '        If ActiveDocument.Sections(sec).Application.Selection. _
    '        HeaderFooter.LinkToPrevious = False Then
    '            InsertFooter
    '        End If
    '    End With
    '    If sec < sCount Then ActiveWindow.ActivePane.View.NextHeaderFooter
    'Next sec
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

Sub InsertFooter()
    Selection.EndKey Unit:=wdStory
    Selection.TypeParagraph
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    Selection.Font.Size = 8
    NormalTemplate.AutoTextEntries("Filename 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

HTH
dragontooth


Avatar of Joanne M. Orzech

ASKER

Awesome Dragontooth!  It works great except it puts four footers on each page....
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!
ASKER CERTIFIED SOLUTION
Avatar of Tommy Kinard
Tommy Kinard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are awesome!!!!  Excellent work Dragontooth.  Increased points for ya ;)

Thanks again.

Joanne

Thanks for the Points and the Grade!!

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
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

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
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

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?
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