fumei
Fri Feb 29 11:58:08 PST 2008
A bit more clarity may help.
Why are you making DifferentFirstPage? If the TOC is in its own Section - a
good idea - then just put the footer for it, into it. Whether it is 1 page,
or 3 pages, or 4 pages, they will all have the same footer. For example:
Sub MyToCMarker()
Dim oHF As HeaderFooter
Dim var
With Selection
.HomeKey Unit:=wdStory
.InsertBreak Type:=wdSectionBreakNextPage
.MoveLeft Unit:=wdCharacter, Count:=1
ActiveDocument.Bookmarks.Add Name:="ToC_Here", _
Range:=Selection.Range
For var = 1 To 3
Set oHF = ActiveDocument.Sections(2).Footers(var)
oHF.LinkToPrevious = False
Next
.Sections(1).Footers(wdHeaderFooterPrimary).Range _
.Text = "This is ToC footer"
End With
End Sub
Sub MakeMyToC()
Selection.GoTo What:=wdGoToBookmark, Name:="ToC_Here"
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, _
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, _
AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True, _
UseOutlineLevels:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
End Sub
What these do.
Sub MyToCMarker()
goes to the start of the document
makes a Section break
backs into the Section it just made
adds a bookmark (to mark where the ToC is going to go)
makes all the footer of the NEXT Section (the one now AFTER the TOC Section)
LinkToPrevious = False. This ensures any EXISTING footers remain correct.
adds the text for the TOC footer
Sub MakeMyToC()
goes to the bookmark where you want the ToC
makes the ToC - note: default parameters used
Now you can make the ToC Section on its own, and when you ready...make the
ToC.
Again, it makes no difference if the the ToC is 1 page...or expands to 123
pages. The ToC section will its own footer.
Grenier wrote:
>Automating a word report. the TOC can take the space of 1 to 3 pages long.
>I'm looking for the correct way to insert the TOC on page 3 of the report.
>
>When I build the report, I leave page 3 empty (sectionbreak in top of page)
>, set all the toc field in the following pages and once done, I return or
>goto page 3 and then add the TOC. The problem that I have is with the footer
>of pages containing the TOC. If the TOC has just one page, the footer is OK.
>If the TOC has 2 or more pages, the footer is not repeated. (probably because
>no section break ?) here's the step I coded...
>
>.DifferentFirstPageHeaderFooter = True
>page1 :no footer
>page2 :add custum footer, wdHeaderFooterFirstPage, LinkToPrevious=false
>page3 : insert TOC, wdHeaderFooterPrimary, LinkToPrevious=true
> ...suppose toc is 3 pages long
>page4 : no footer
>page5 : no footer
>page6 : add custum footer, wdHeaderFooterFirstPage, LinkToPrevious=false OK
>
>How can I get a footer on page 4 and 5. Can I force footer to appear on each
>page instead of each section cause the problem here is that the section is 3
>pages long.
>Maybe it's not the way to do it ? and hoping I'm clear...
>
>Merci !
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200802/1