G
Greg Maxey
Today I was playing around with a macro to add a new section and kill
the link to previous header and footer.
Some apparently working code is posted at the end of this message if
anyone is interested.
While working on the macro, I first thought that I would use the
HeaderFooter property. Word help says"
Returns a HeaderFooter object for the specified selection or range.
Read-only.
Note An error occurs if the selection isn't located within a header
or footer.
Key terms are "specified selection or RANGE" and "if the selection
ISN'T located within a header or footer"
I think I met that criteria with the code below and get the error:
Method or data member not found on line using the HeaderFooter
property.
Sub AddSectionAndKillLinkToPrevious3()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
Set myRng = oDoc.Sections(i).Headers(wdHeaderFooterPrimary).Range
myRng.Select
myRng.HeaderFooter.LinkToPrevious = False
End With
End Sub
It seems that HeaderFooter will only be accepted as a propert of a
specified Selecton. Am I missing something?
Code that seems to work:
Sub AddSectionAndKillLinkToPrevious()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
With oDoc.Sections(i)
For j = 1 To 3
.Headers(j).LinkToPrevious = False
.Footers(j).LinkToPrevious = False
Next j
End With
End Sub
the link to previous header and footer.
Some apparently working code is posted at the end of this message if
anyone is interested.
While working on the macro, I first thought that I would use the
HeaderFooter property. Word help says"
Returns a HeaderFooter object for the specified selection or range.
Read-only.
Note An error occurs if the selection isn't located within a header
or footer.
Key terms are "specified selection or RANGE" and "if the selection
ISN'T located within a header or footer"
I think I met that criteria with the code below and get the error:
Method or data member not found on line using the HeaderFooter
property.
Sub AddSectionAndKillLinkToPrevious3()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
Set myRng = oDoc.Sections(i).Headers(wdHeaderFooterPrimary).Range
myRng.Select
myRng.HeaderFooter.LinkToPrevious = False
End With
End Sub
It seems that HeaderFooter will only be accepted as a propert of a
specified Selecton. Am I missing something?
Code that seems to work:
Sub AddSectionAndKillLinkToPrevious()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
With oDoc.Sections(i)
For j = 1 To 3
.Headers(j).LinkToPrevious = False
.Footers(j).LinkToPrevious = False
Next j
End With
End Sub