Microsoft Office Forums Mail merged document and page numbers for table of contents

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 04-07-2016, 03:09 AM
macropod's Avatar
macropod macropod is offline Mail merged document and page numbers for table of contents Windows 7 64bit Mail merged document and page numbers for table of contents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Having seen your document, it is evident that simply deleting Section breaks will compromise its layout. The following code should achieve the desired result:
Code:
Sub LinkSections()
Application.ScreenUpdating = False
Dim HdFt As HeaderFooter, Rng As Range, Sctn As Section
With ActiveDocument
  If .Sections.Count > 1 Then
    For Each HdFt In .Sections(.Sections.Count).Headers
      If HdFt.Exists Then
        If Len(.Sections(1).Headers(HdFt.Index).Range) > 1 Then
          HdFt.Range.FormattedText = .Sections(1).Headers(HdFt.Index).Range.FormattedText
          HdFt.Range.Characters.Last.Delete
        End If
      End If
    Next
    For Each HdFt In .Sections(.Sections.Count).Footers
      If HdFt.Exists Then
        If Len(.Sections(1).Footers(HdFt.Index).Range) > 1 Then
          HdFt.Range.FormattedText = .Sections(1).Footers(HdFt.Index).Range.FormattedText
          HdFt.Range.Characters.Last.Delete
        End If
      End If
    Next
  End If
  For Each Sctn In .Sections
    For Each HdFt In Sctn.Headers
      If HdFt.Exists Then
        HdFt.LinkToPrevious = True
        HdFt.PageNumbers.RestartNumberingAtSection = False
      End If
    Next
    For Each HdFt In Sctn.Footers
      If HdFt.Exists Then
        HdFt.LinkToPrevious = True
        HdFt.PageNumbers.RestartNumberingAtSection = False
      End If
    Next
  Next
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub

__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #17  
Old 04-07-2016, 03:12 AM
jab40 jab40 is offline Mail merged document and page numbers for table of contents Windows 7 32bit Mail merged document and page numbers for table of contents Office 2010 32bit
Novice
Mail merged document and page numbers for table of contents
 
Join Date: Jul 2011
Posts: 15
jab40 is on a distinguished road
Default

This has worked perfectly, thank you so much Paul, that's exactly what I needed, thank you so much for your help.

Having seen my document, are you also able to advise why the table on contents doesn't pull formatting (font, colour, size, styles) from the main document?
Reply With Quote
  #18  
Old 04-07-2016, 03:34 AM
macropod's Avatar
macropod macropod is offline Mail merged document and page numbers for table of contents Windows 7 64bit Mail merged document and page numbers for table of contents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

The Table of Contents formatting looks OK to me. From what I can see, font colours are being preserved (e.g. for YR3Peripheral vascular disease [PVD] 32). Do note that the Table of Contents formatting is controlled by whatever is applied to the relevant TOC Styles, not by the Heading Styles. So, if you want to apply Small Caps, as per the headings, you need to modify the corresponding TOC Styles.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #19  
Old 04-07-2016, 04:57 AM
jab40 jab40 is offline Mail merged document and page numbers for table of contents Windows 7 32bit Mail merged document and page numbers for table of contents Office 2010 32bit
Novice
Mail merged document and page numbers for table of contents
 
Join Date: Jul 2011
Posts: 15
jab40 is on a distinguished road
Default

Thank you, I'll look into that.

The only issue I'm having with that macro now is that, now when I save the document, it asks me if I want to overwrite the the saved document with 'this new version' -- any ideas why?
Reply With Quote
  #20  
Old 04-07-2016, 05:20 AM
macropod's Avatar
macropod macropod is offline Mail merged document and page numbers for table of contents Windows 7 64bit Mail merged document and page numbers for table of contents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Nothing in the code re-write would affect the save behaviour. Perhaps you previously added the code to the mailmerge main document, but now you've added it to the mailmerge output document?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #21  
Old 04-07-2016, 08:25 AM
jab40 jab40 is offline Mail merged document and page numbers for table of contents Windows 7 32bit Mail merged document and page numbers for table of contents Office 2010 32bit
Novice
Mail merged document and page numbers for table of contents
 
Join Date: Jul 2011
Posts: 15
jab40 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The Table of Contents formatting looks OK to me. From what I can see, font colours are being preserved (e.g. for YR3Peripheral vascular disease [PVD] 32). Do note that the Table of Contents formatting is controlled by whatever is applied to the relevant TOC Styles, not by the Heading Styles. So, if you want to apply Small Caps, as per the headings, you need to modify the corresponding TOC Styles.
Another problem solved -- thanks so much for your help!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail merged document and page numbers for table of contents Cannot Update Page Numbers Only on Table of Contents CrossReach Word 8 03-09-2016 01:18 PM
Mail merged document and page numbers for table of contents Table of Contents - page numbers not aligned to the right in longer headings krneki Word 3 08-17-2015 08:34 AM
Mail merged document and page numbers for table of contents Align Mail Merged Numbers to the Decimal Point HangMan Mail Merge 1 12-11-2013 02:32 PM
Mail merged document and page numbers for table of contents Page Numbers in Table of Contents MerRob54 Word 6 01-28-2013 03:37 AM
Mail merged document and page numbers for table of contents decimal numbers not appearing properly in merged document paulys Mail Merge 2 08-06-2012 08:15 AM


All times are GMT -7. The time now is 11:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft