Macro to discontinue next section's header/footer

R

Raj

In a document, when i try insert a new section at the beging of the document through the following macros. All the header/footers of even page is disappearing

But I want this newly inserted section alone to have no heaer/footer. while my old section should retain its header/footer as it is

here is what i am trying, but this code deletes all the header/foote

Selection.InsertBreak Type:=wdPageBrea
Selection.InsertBreak Type:=wdSectionBreakNextPag
WordBasic.LineUp
WordBasic.Style "PartNo
WordBasic.Insert "New Part
WordBasic.NormalStyl

WordBasic.nextpag
WordBasic.nextpag
WordBasic.nextpag

With Selection.Sections(1).Headers(wdHeaderFooterEvenPages
.LinkToPrevious = Fals
End Wit

WordBasic.prevpag
WordBasic.prevpag

With Selection.Sections(1).Headers(wdHeaderFooterPrimary
.LinkToPrevious = Fals
.Range.Delet
End Wit
WordBasic.CloseViewHeaderFoote

Please help...
 
D

Doug Robbins - Word MVP

I would suggest that you get rid of all of the WordBasic commands (whatever
they do)

The following will insert a section break at the beginning of the document,
unlink the header in the second section from the first and then delete
anything that is in the header in the first section

Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.Collapse wdCollapseStart
myrange.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Sections(2).Headers(wdHeaderFooterEvenPages).LinkToPrevious =
False
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Raj said:
In a document, when i try insert a new section at the beging of the
document through the following macros. All the header/footers of even page
is disappearing.
But I want this newly inserted section alone to have no heaer/footer.
while my old section should retain its header/footer as it is.
 
R

Raj

Thanks for your answer. any particular reason why to get rid of those wordbasic commands

since i am inserting the section break at the begining of my document, i slighly modified it by addin

ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).LinkToPrevious = Fals

now it works fin

once again many thank

now i am using this one

Dim myrange As Rang
Set myrange = ActiveDocument.Rang
myrange.Collapse wdCollapseStar
myrange.InsertBreak Type:=wdSectionBreakNextPag
ActiveDocument.Sections(2).Headers(wdHeaderFooterFirstPage).LinkToPrevious = Fals
ActiveDocument.Sections(2).Headers(wdHeaderFooterEvenPages).LinkToPrevious = Fals
ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).LinkToPrevious = Fals
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete
 

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