Solved

Filename and path footer on every page of every section of document in Word 2000

Posted on 2003-12-02
13
1,558 Views
Last Modified: 2012-05-04
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:

http://www.experts-exchange.com/Applications/MS_Office/Word/Q_20794791.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!
0
Comment
Question by:Joanne M. Orzech
  • 6
  • 5
  • 2
13 Comments
 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
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


0
 
LVL 37

Author Comment

by:Joanne M. Orzech
Comment Utility
Awesome Dragontooth!  It works great except it puts four footers on each page....
0
 
LVL 37

Author Comment

by:Joanne M. Orzech
Comment Utility
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!
0
 
LVL 14

Accepted Solution

by:
Tommy Kinard earned 500 total points
Comment Utility
Hi JOrzech,

I thought that would happen - I test with one section and LOL here we go.
Anyway I don't think the quantity of sections has anything to do with the footers so lets take it out and try that one. The folowing is the revised code without the comment and etc. Indented because it was easier for me to read.


 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
    While Err.Number = 0
        With ActiveDocument.Sections
            If .Application.Selection.HeaderFooter.LinkToPrevious = False Then  '< removed the ActiveDocument.Sections - you used with already no need to repeat
                InsertFooter
            End If
        End With
        On Error Resume Next
        ActiveWindow.ActivePane.View.NextHeaderFooter
    Wend
    Err.Clear
    On Error GoTo 0
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

HTH
dragontooth

0
 
LVL 37

Author Comment

by:Joanne M. Orzech
Comment Utility
You are awesome!!!!  Excellent work Dragontooth.  Increased points for ya ;)

Thanks again.

Joanne

0
 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
Thanks for the Points and the Grade!!

dragontooth

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 21

Expert Comment

by:EricFletcher
Comment Utility
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
0
 
LVL 37

Author Comment

by:Joanne M. Orzech
Comment Utility
But page footers change from section to section
0
 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
@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

0
 
LVL 21

Expert Comment

by:EricFletcher
Comment Utility
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
0
 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
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.

http://www.experts-exchange.com/Applications/MS_Office/Word/Q_20827584.html

dragontooth

0
 
LVL 37

Author Comment

by:Joanne M. Orzech
Comment Utility
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?
0
 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now