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

--------------------------------------------------------------------------------------------------------------------------

Can any one tel me what I am doing wrong - Please

Ebbe

Re: Problems with headers/footers by Doug

Doug
Tue Jun 21 13:24:25 CDT 2005

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
"Ebbe" <REMOVE_CAPSebFbHe@iRnGdbHaHkDSke.dRk> wrote in message
news:%23AAcPsodFHA.1036@tk2msftngp13.phx.gbl...
> 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
>
> --------------------------------------------------------------------------------------------------------------------------
>
> Can any one tel me what I am doing wrong - Please
>
> Ebbe
>



Re: Problems with headers/footers by Ebbe

Ebbe
Tue Jun 21 15:01:54 CDT 2005

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

"Doug Robbins" <dkr@REMOVEmvps.org> wrote in message
news:eAj635odFHA.2288@TK2MSFTNGP14.phx.gbl...
> 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
> "Ebbe" <REMOVE_CAPSebFbHe@iRnGdbHaHkDSke.dRk> wrote in message
> news:%23AAcPsodFHA.1036@tk2msftngp13.phx.gbl...
>> 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
>>
>> --------------------------------------------------------------------------------------------------------------------------
>>
>> Can any one tel me what I am doing wrong - Please
>>
>> Ebbe
>>
>
>




Re: Problems with headers/footers by Ebbe

Ebbe
Tue Jun 21 15:12:05 CDT 2005

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

"Doug Robbins" <dkr@REMOVEmvps.org> skrev i en meddelelse
news:eAj635odFHA.2288@TK2MSFTNGP14.phx.gbl...
> 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
> "Ebbe" <REMOVE_CAPSebFbHe@iRnGdbHaHkDSke.dRk> wrote in message
> news:%23AAcPsodFHA.1036@tk2msftngp13.phx.gbl...
>> 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
>>
>> --------------------------------------------------------------------------------------------------------------------------
>>
>> Can any one tel me what I am doing wrong - Please
>>
>> Ebbe
>>
>
>