W
Wes
I'm having problems with headers/footers that are linked to previous. My
test document is a document with 4 sections, with the section footer 2 linked
to 1 and section footer 4 linked to 3.
When I run this, moving to the section 2, moving to the footer puts me up in
the footer for section 1, which is fine as 2 is linked to one. However, the
next iteration moves to section 3, then moving to the footer puts me in the
footer for section 2, where my insert is duplicated.
Any help would be appreciated. Thanks.
Here is the code:
SecCt = ActiveWindow.ActivePane.Document.Sections.Count
Err.Clear
For s = 1 To SecCt 'Loop through the sections 1.1
Selection.GoTo what:=wdGoToSection, which:=wdGoToAbsolute, Count:=s
'Move focus to next section
For h = 1 To 3 'three header types
Select Case h '1.1.1
Case 1
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryFooter
Case 2
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageFooter
Case 3
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesFooter
End Select 'End 1.1.1
If Err.Number = 5895 Then 'Check if footer type exists '1.1.2
Err.Clear
Else '1.1.2
With Selection '1.1.2.1
i = 0
If
(ActiveDocument.Sections(s).Footers(h).LinkToPrevious) = True Then
doInsert = False
Else
doInsert = True
Do
.MoveRight unit:=wdSentence, Extend:=wdExtend
If .Find.Execute(FindText:=OrigDocID,
ReplaceWith:=NewVersion, Replace:=wdReplaceAll) = True Then
doInsert = False
.Font.Name = "Arial"
.Font.Size = 8
End If
.MoveDown
i = i + 1
Loop Until Selection.HeaderFooter.IsHeader = True Or
i = 5
End If
If doInsert Then
.HomeKey
.MoveUp
If Selection.HeaderFooter.IsHeader = True Then
.MoveDown
End If
.Font.Name = "Arial"
.Font.Size = 8
.InsertBefore (NewVersion & " ")
End If
End With 'End 1.1.2.1
End If
Next h
Next s 'Loop through the sections 1.1
test document is a document with 4 sections, with the section footer 2 linked
to 1 and section footer 4 linked to 3.
When I run this, moving to the section 2, moving to the footer puts me up in
the footer for section 1, which is fine as 2 is linked to one. However, the
next iteration moves to section 3, then moving to the footer puts me in the
footer for section 2, where my insert is duplicated.
Any help would be appreciated. Thanks.
Here is the code:
SecCt = ActiveWindow.ActivePane.Document.Sections.Count
Err.Clear
For s = 1 To SecCt 'Loop through the sections 1.1
Selection.GoTo what:=wdGoToSection, which:=wdGoToAbsolute, Count:=s
'Move focus to next section
For h = 1 To 3 'three header types
Select Case h '1.1.1
Case 1
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryFooter
Case 2
ActiveWindow.ActivePane.View.SeekView =
wdSeekFirstPageFooter
Case 3
ActiveWindow.ActivePane.View.SeekView =
wdSeekEvenPagesFooter
End Select 'End 1.1.1
If Err.Number = 5895 Then 'Check if footer type exists '1.1.2
Err.Clear
Else '1.1.2
With Selection '1.1.2.1
i = 0
If
(ActiveDocument.Sections(s).Footers(h).LinkToPrevious) = True Then
doInsert = False
Else
doInsert = True
Do
.MoveRight unit:=wdSentence, Extend:=wdExtend
If .Find.Execute(FindText:=OrigDocID,
ReplaceWith:=NewVersion, Replace:=wdReplaceAll) = True Then
doInsert = False
.Font.Name = "Arial"
.Font.Size = 8
End If
.MoveDown
i = i + 1
Loop Until Selection.HeaderFooter.IsHeader = True Or
i = 5
End If
If doInsert Then
.HomeKey
.MoveUp
If Selection.HeaderFooter.IsHeader = True Then
.MoveDown
End If
.Font.Name = "Arial"
.Font.Size = 8
.InsertBefore (NewVersion & " ")
End If
End With 'End 1.1.2.1
End If
Next h
Next s 'Loop through the sections 1.1