Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

HeaderFooter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 28 Apr 2006 15:53 GMT
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
Doug Robbins - Word MVP - 28 Apr 2006 19:49 GMT
Hi Greg,

Here is another way:

Dim i As Long
Dim j As Long
Dim hf As HeaderFooter
Dim oDoc As Document
Dim myRng As 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
For Each hf In oDoc.Sections(i).Headers
   hf.LinkToPrevious = False
Next hf
For Each hf In oDoc.Sections(i).Footers
   hf.LinkToPrevious = False
Next hf

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Today I was playing around with a macro to add a new section and kill
> the link to previous header and footer.
[quoted text clipped - 53 lines]
> End With
> End Sub
Greg Maxey - 28 Apr 2006 22:16 GMT
Yep, that works equally well.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
>
[quoted text clipped - 73 lines]
>> End With
>> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.