I am using VBA in Word 2003 to programmatically edit the headers of my document. My header paragraph style includes a bottom border.
Page one (section 1) does not use a header. However, when I programmatically edit the header of section 2, the bottom border shows up in the header of section 1 (even though there is no text). The following attempts have not fixed the problem:
The only workaround I have found is to view the headers/footers (change the SeekView property), and then return to the print view. The problem is that, even with ScreenUpdating disable, the screen briefly flashes the headers/footers editing window. Here is my code:
Can anyone suggest a way to fix this problem without having to alter the Seek View? I would really appreciate your help.
Page one (section 1) does not use a header. However, when I programmatically edit the header of section 2, the bottom border shows up in the header of section 1 (even though there is no text). The following attempts have not fixed the problem:
Code:
With ThisDocument
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = ""
.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Text = ""
.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Text = ""
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete
.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Delete
.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Delete
End With ' ThisDocument
Code:
Public Sub EditHeaders(strNameProject$, strNameChapter$, intChapter%)
'
' Object variables:
' sct = Used to iterate through sections.
Dim sct As Section
Application.ScreenUpdating = False
For Each sct In ThisDocument.Sections
If Not sct.Index = 1 Then _
sct.Headers(wdHeaderFooterPrimary).Range.Text = strNameProject & Chr(12) & _
intChapter & ".0 " & strNameChapter
Next ' sct
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then ActiveWindow.Panes(2).Close
ActiveWindow.ActivePane.View.Type = wdPrintView
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Application.ScreenUpdating = True
End Sub