Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

why does my header footer get shunted to last section?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 31 May 2005 16:17 GMT
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
Charles Kenyon - 31 May 2005 16:25 GMT
Hi Rob,

Headers and footers are section properties. So, if you copy sections from
another document into your document, you will bring along any header/footer
properties of those sections.
http://word.mvps.org/FAQs/Formatting/WorkWithSections.htm
http://word.mvps.org/FAQs/Formatting/PasteWithoutSectionInfo.htm
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Hello. Good forum, glad I found you.
> Anyway can you help me?
[quoted text clipped - 93 lines]
> I am using Word 2003 if it matters.
> Rob
Rob - 31 May 2005 17:23 GMT
Thankyou Charles. Now you've given me the why and the how of it, I think I
can get it sorted - need to look at the last para mark and/or move section
with my header so is not the first -Knew this was a good forum.
Rob - 06 Jun 2005 15:47 GMT
I ended up just copying the header group from the last section and pasting
it into the first. To do so I found below code useful, letting you assign a
name to a shape or group -in my case the group in the header footer I
needed to copy. I'm not sure whose code it originally was.

Sub NameShape()

'select a shape and run this macro to rename the shape
   Dim Name$
   On Error GoTo AbortNameShape
       If ActiveWindow.Selection.ShapeRange.Count = 0 Then
       MsgBox "No Shapes Selected"
       Exit Sub
   End If
   Name$ = ActiveWindow.Selection.ShapeRange(1).Name
   Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)
   If Name$ <> "" Then
       ActiveWindow.Selection.ShapeRange(1).Name = Name$
   End If
   Exit Sub
AbortNameShape:
   MsgBox Err.Description
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.