Inserting a different header for each section

  • Thread starter Stephen English
  • Start date
S

Stephen English

Hi
I was hoping that the last line of code below would allow me to insert a
different header for each section like you can do manually. But each time I
chage it, it changes the headers on every page in the document to be the new
one!

Any ideas please?
Stephen

Dim rTmp1 As Word.Range
Dim rtmp2 As Word.Range
Dim sTmp As String
Dim lTmp As Long
Dim lTmpr As Long

sTmp = "YEAR " & rsYears!Year & vbCrLf
With docMaster.Bookmarks("Start")
lTmpr = Len(.Range)
Set rTmp1 = .Range
.Delete
End With
With rTmp1
.InsertBreak Type:=wdSectionBreakNextPage
intSection = intSection + 1
.InsertBefore sTmp
.Start = .Start + Len(sTmp)
.Bookmarks.Add "Start"
End With

docMaster.Sections(intSection).Headers(wdHeaderFooterPrimary).Range.Text =
"YEAR " & rsYears!Year
 
S

Stefan Blom

You will have to unlink each type of header before adding contents to them.
For example:

Dim s As Section
For Each s In ActiveDocument.Sections
s.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
s.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
s.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
Next s
 

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