R
Rob via OfficeKB.com
Hello. Good forum, glad I found you.
Anyway can you help me?
I need to copy a client's doc (and its sections) into a second doc and have
my header/footer appear on all pages for all sections - I'm having trouble.
When I paste the content into the second document my header/footer only
ever appears in the very last section of the document. The other sections
have no header/footer.
If there is no quick and easy, then this is the detail:
Both docs are open. Only the client's doc has sections. It has no
headers/footers - I have deleted them all and set every section's
headers/footers to 'same as previous'. First page is not different. The
second doc is new from a template and has my header/footer (text, textbox,
bookmarks, page numbers and grouped graphics set not to move with text) and
no sections. First page is not different.
So why does my header/footer get shunted to the very last section instead
of appearing on every page? (And in doing so Word changes removes the link
to previous). Can anyone help?
This is the code I'm using:
' Someones posted code that deletes header/footers, seems to work.
Dim h As HeaderFooter, f As HeaderFooter, s As Section
For Each s In ActiveDocument.Sections
For Each h In s.Headers
h.Range.Delete
Next
For Each f In s.Footers
f.Range.Delete
Next
Next
' I use this to copy and paste in the text
' select and copy all text
Set DonorRange = ActiveDocument.Content
With DonorRange.Copy
End With
' close the document that user wants to insert
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' with focus back on my doc create bookmark at start point
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Story1"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
' paste clipboard content into new doc
ActiveDocument.Bookmarks("Story1").Range.Paste
'Again someone else's code to make all headers the same- works in client
doc but doesn't in my second doc (after I've pasted in the content) -get
Runtime Error 4605 at "hdr1.LinkToPrevious = True" bits . I run similar for
footers with same error. Even if it did work, my header/footer at end of
doc so would likely be deleted?
Dim i As Long
Dim hdr As HeaderFooter
Dim sec As Section
With ActiveDocument
For i = 1 To .Sections.Count
'loop through each section in the
'document looking for your marker
'if found, run following code --
'make sure you IF test or SELECT CASE
'before executingg the following code so
'it doesn't run on all sections
'make sure header is linked to previous
For Each hdr1 In .Sections(i).Headers
hdr1.LinkToPrevious = True
Next hdr1
'then make sure header in following
'section is linked to this section
If i <> .Sections.Count Then
For Each hdr1 In .Sections(i + 1).Headers
hdr1.LinkToPrevious = True
Next hdr1
End If
Next
End With
I am using Word 2003 if it matters.
Rob
Anyway can you help me?
I need to copy a client's doc (and its sections) into a second doc and have
my header/footer appear on all pages for all sections - I'm having trouble.
When I paste the content into the second document my header/footer only
ever appears in the very last section of the document. The other sections
have no header/footer.
If there is no quick and easy, then this is the detail:
Both docs are open. Only the client's doc has sections. It has no
headers/footers - I have deleted them all and set every section's
headers/footers to 'same as previous'. First page is not different. The
second doc is new from a template and has my header/footer (text, textbox,
bookmarks, page numbers and grouped graphics set not to move with text) and
no sections. First page is not different.
So why does my header/footer get shunted to the very last section instead
of appearing on every page? (And in doing so Word changes removes the link
to previous). Can anyone help?
This is the code I'm using:
' Someones posted code that deletes header/footers, seems to work.
Dim h As HeaderFooter, f As HeaderFooter, s As Section
For Each s In ActiveDocument.Sections
For Each h In s.Headers
h.Range.Delete
Next
For Each f In s.Footers
f.Range.Delete
Next
Next
' I use this to copy and paste in the text
' select and copy all text
Set DonorRange = ActiveDocument.Content
With DonorRange.Copy
End With
' close the document that user wants to insert
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' with focus back on my doc create bookmark at start point
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Story1"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
' paste clipboard content into new doc
ActiveDocument.Bookmarks("Story1").Range.Paste
'Again someone else's code to make all headers the same- works in client
doc but doesn't in my second doc (after I've pasted in the content) -get
Runtime Error 4605 at "hdr1.LinkToPrevious = True" bits . I run similar for
footers with same error. Even if it did work, my header/footer at end of
doc so would likely be deleted?
Dim i As Long
Dim hdr As HeaderFooter
Dim sec As Section
With ActiveDocument
For i = 1 To .Sections.Count
'loop through each section in the
'document looking for your marker
'if found, run following code --
'make sure you IF test or SELECT CASE
'before executingg the following code so
'it doesn't run on all sections
'make sure header is linked to previous
For Each hdr1 In .Sections(i).Headers
hdr1.LinkToPrevious = True
Next hdr1
'then make sure header in following
'section is linked to this section
If i <> .Sections.Count Then
For Each hdr1 In .Sections(i + 1).Headers
hdr1.LinkToPrevious = True
Next hdr1
End If
Next
End With
I am using Word 2003 if it matters.
Rob