looping through sections

S

Susan Taylor

I am using the following code to loop through a document and insert
text into the footers based on the footer type - this works until I
reach the last section - here it inserts the text two times - can
someone assist?


sect_count = ActiveDocument.Sections.count


For count = 1 To sect_count
For Each sect In ActiveDocument.Sections
If sect.footers(wdHeaderFooterFirstPage).Exists Then
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageFooter
'insert first page text

ElseIf sect.footers(wdHeaderFooterEvenPages).Exists Then
ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryFooter
'insert some text

Else: ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'insert some different text
End If


Next
Next

thank you,
Susan Taylor
 
D

Doug Robbins - Word MVP

Hi Susan,

You have two For ... Next statements there where only one is required.

Use:

Dim i As Integer
For i = 1 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).Footers(wdHeaderFooterFirstPage).Exists
Then

ActiveDocument.Sections(i).Footers(wdHeaderFooterFirstPage).Range.Text =
"FirstPageFooterText"
ElseIf ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Exists
Then
ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range.Text
= "PrimaryFooterText"
End If
Next i

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top