coding for new section

J

Julia T.

Hi,

I am trying to create a macro that will: 1) create a new
section at the end of the document for an envelope and 2)
discontinue the headers/footers in the previous sections.
When I do this as I am recording the macro, it works
great. However, when I run the macro it deletes the
footer in the first section of the document. I promise I
know how headers and footers work.

I have the following code:

Sub Test()
'
'THIS GOES TO THE END AND CREATES THE NEW SECTION
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.InsertBreak Type:=wdSectionBreakNextPage

'THIS CREATES A NEW BLANK HEADER AND FOOTER IN THE NEW
(LAST) SECTION

ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = Not
Selection.HeaderFooter. _
LinkToPrevious
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
End If
Selection.HeaderFooter.LinkToPrevious = Not
Selection.HeaderFooter. _
LinkToPrevious
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
End Sub


I would be gratefull for any ideas - I've been working for
days on this. . .
Thanks
 
P

Peter Hewett

Hi Julia

You can try this code. It inserts a new section break and severs all
header/footer links to the prevous section regardless of whether a
particular header/footer type was being used:

Public Sub InsertNewSection()
With Selection
.EndKey Unit:=wdStory
.TypeParagraph
.InsertBreak Type:=wdSectionBreakNextPage

.Collapse wdCollapseEnd
With .Sections(1)
.Headers(1).LinkToPrevious = False
.Headers(2).LinkToPrevious = False
.Headers(3).LinkToPrevious = False
.Footers(1).LinkToPrevious = False
.Headers(2).LinkToPrevious = False
.Headers(3).LinkToPrevious = False
End With
End With
End Sub

HTH + Cheers - Peter
 
J

Julia

Thanks a million!!

-----Original Message-----
Hi Julia

You can try this code. It inserts a new section break and severs all
header/footer links to the prevous section regardless of whether a
particular header/footer type was being used:

Public Sub InsertNewSection()
With Selection
.EndKey Unit:=wdStory
.TypeParagraph
.InsertBreak Type:=wdSectionBreakNextPage

.Collapse wdCollapseEnd
With .Sections(1)
.Headers(1).LinkToPrevious = False
.Headers(2).LinkToPrevious = False
.Headers(3).LinkToPrevious = False
.Footers(1).LinkToPrevious = False
.Headers(2).LinkToPrevious = False
.Headers(3).LinkToPrevious = False
End With
End With
End Sub

HTH + Cheers - Peter




.
 

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