Problems with headers/footers

E

Ebbe

Hey!

I have a document with some textboxes and graphic elements (shapes) in the
header. These shapes is repeated on each page.
But I want to insert some other document in the middle of the document and
preserve the shapes on both sides of this inserted document.

Standing on page 1, I want to insert a page (another document) as page 2.
Page 3 should have the same header/footer as page 1.

Here is what I am doing and what I see:
--------------------------------------------------------------------------------------------------------------------------
Sub InsertDocumentAfterPage()
Dim i As Integer
'---- Standing on page 1

'---- New page 2 gets the same shapes as page x
Selection.InsertBreak Type:=wdSectionBreakNextPage

'---- Cutting the link to page 1
ActiveDocument.Sections(ActiveDocument.Sections.Count).Headers(wdHeaderFooterPrimary).LinkToPrevious
= False
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).LinkToPrevious
= False

'---- New page 3 gets the same shapes as page 2
Selection.InsertBreak Type:=wdSectionBreakNextPage

'---- Cutting the link to page 2

ActiveDocument.Sections(ActiveDocument.Sections.Count).Headers(wdHeaderFooterPrimary).LinkToPrevious
= False
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).LinkToPrevious
= False

'---- Trying to delete all shapes in header of page 2 (!!!! but the shapes
is removed on ALL pages !!!!)
i = ActiveDocument.Sections(ActiveDocument.Sections.Count -
1).Headers(wdHeaderFooterPrimary).Shapes.Count
While i > 0
ActiveDocument.Sections(ActiveDocument.Sections.Count -
1).Headers(wdHeaderFooterPrimary).Shapes(i).Delete
i = i - 1
Wend

'---- Moving to end of page 2
Selection.MoveLeft Count:=1

'---- Inserting an other document on page 2
Selection.InsertFile
FileName:="d:\XALKun\Seelen\EG_X2W\SeelenFakHanbet.doc", _
Range:="", ConfirmConversions:=False, Link:=False, _
Attachment:=False

'---- Moving to end of story on page 3
Selection.EndKey Unit:=wdStory

End Sub
 
D

Doug Robbins

You need to insert a Section Break, unlink the header for the Section after
that Section Break, the insert another Section Break before that one, unlink
the header from that one, and remove the header, then insert the new
document between the Section Breaks that were just added.

All of your operations are being done on the last Section in the document
(ActiveDocument.Sections.Count)

--
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
 
E

Ebbe

Hey Doug

Now I have rewritten the script after what I understand of Your advice.
But the result is the same.
---------------------------------------------------------------------------------------
Sub InsertDocumentAfterPage()
Dim i As Integer

Selection.InsertBreak Type:=wdSectionBreakNextPage

With ActiveDocument.Sections(ActiveDocument.Sections.Count)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With

Selection.MoveLeft Count:=1

Selection.InsertBreak Type:=wdSectionBreakNextPage

With ActiveDocument.Sections(ActiveDocument.Sections.Count)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With


With ActiveDocument.Sections(ActiveDocument.Sections.Count - 1)
i = .Headers(wdHeaderFooterPrimary).Shapes.Count
While i > 0
.Headers(wdHeaderFooterPrimary).Shapes(i).Delete
i = i - 1
Wend
End With

Selection.InsertFile
FileName:="d:\XALKun\Seelen\EG_X2W\SeelenFakHanbet.doc", _
Range:="", ConfirmConversions:=False, Link:=False, _
Attachment:=False

Selection.EndKey Unit:=wdStory

End Sub
---------------------------------------------------------------------------------------
Afterwards I have discovered the headers is not unlinked in spite of setting
LinkToPrevious = False.
When i afterwards manually unlink the headers after executing the two
wdSectionBreakNextPage's,
the number of shapes in the header tripled from 32 to 96!
I conclude, that the way I try to unlink the headers is wrong.
How do I do it correctly?

Ebbe
 
E

Ebbe

Hey Doug

Now I have rewritten the script after what I understand of your advice.
But the result is the same.
---------------------------------------------------------------------------------------
Sub InsertDocumentAfterPage()
Dim i As Integer

Selection.InsertBreak Type:=wdSectionBreakNextPage

With ActiveDocument.Sections(ActiveDocument.Sections.Count)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With

Selection.MoveLeft Count:=1

Selection.InsertBreak Type:=wdSectionBreakNextPage

With ActiveDocument.Sections(ActiveDocument.Sections.Count)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With


With ActiveDocument.Sections(ActiveDocument.Sections.Count - 1)
i = .Headers(wdHeaderFooterPrimary).Shapes.Count
While i > 0
.Headers(wdHeaderFooterPrimary).Shapes(i).Delete
i = i - 1
Wend
End With

Selection.InsertFile
FileName:="d:\XALKun\Seelen\EG_X2W\SeelenFakHanbet.doc", _
Range:="", ConfirmConversions:=False, Link:=False, _
Attachment:=False

Selection.EndKey Unit:=wdStory

End Sub
---------------------------------------------------------------------------------------
Afterwards I have discovered the headers is not unlinked in spite of setting
LinkToPrevious = False.
When I afterwards manually unlink the headers after executing the two
wdSectionBreakNextPage's,
the number of shapes in the header tripled from 32 to 96!
I conclude, that the way I try to unlink the headers is wrong.
How do I do it correctly?

Ebbe
 

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