Hello. Oh, I have a problem. I need to loop through all types of footers in a multi-section, multi footer document. This document has several sections and each section has all the footer types: FirstPage, EvenPage and Primary.
My code below can show you how i'm not the smartest knife in the drawer so any help will be welcome.
I have a For/Next to loop through the sections and inside I have a DO/While that loops through the types of footer.
So, I go to the first section and open the primary fotoer to see if it's empty. I fnot empty, I have to go through each type of footer to search for a document number. This is the problem. The statement:
ActiveDocument.Sections(i).Footer(swfootercount).Range.Select
always wants to go to section one no matter what values the "For" variable "i" has. Any ideas?
My code below can show you how i'm not the smartest knife in the drawer so any help will be welcome.
I have a For/Next to loop through the sections and inside I have a DO/While that loops through the types of footer.
So, I go to the first section and open the primary fotoer to see if it's empty. I fnot empty, I have to go through each type of footer to search for a document number. This is the problem. The statement:
ActiveDocument.Sections(i).Footer(swfootercount).Range.Select
always wants to go to section one no matter what values the "For" variable "i" has. Any ideas?
Code:
For i = 1 To ActiveDocument.Sections.Count
Selection.GoTo wdgotoselection, wdGoToAbsolute, i
ActiveDocument.Sections(i).Footers_
(wdHeaderFooterPrimary).Range.Select
Selection.HomeKey unit:=wdLine
'if the footer is empty, then I can't move the cursor
swfooterempty = Selection.MoveRight(wdCharacter, 1)
'I'm done evaluating the footer so I'll close it so it
'won't interfere with edits.
ActiveWindow.View.Type = wdPageView
WordBasic.closeviewheaderfooter
ActiveWindow.View.Type = wdPageView
'If the footer is populated we want to loop
'through all 3 types of footers:
'(Primary, FirstPage, and EvenPage) and search for the
'document number in it
If swfooterempty = 1 Then
'Search for document number
'I'll do this until 4 because there are 3 types
'of footer I want to check
Do Until swfootercount = 4
'The following is the statement that doesn't work
ActiveDocument.Sections(i).Footers_
(swfootercount).Range.Select
'Do other stuff, etc.
swfootercount=swfootercount+1
Loop
end if
Next i