Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Wisconsin, USA
    Posts
    193
    Thanks
    0
    Thanked 1 Time in 1 Post

    Macro to Update TOC/Print (2000/SP3)

    I've created a macro that when doing Control+P (or File+Print) will set a bookmark, go to the TOC and update it then go back to the newly create bookmark and have the print dialog box open. Right now, it will do everything except update the TOC. Is what I'm trying to accomplish doable? This is what I have so far:

    Sub FilePrint()
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:="Start"
    End With
    Selection.GoTo What:=wdGoToBookmark, Name:="TOC"
    Selection.Fields.Update
    With ActiveDocument.Bookmarks
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With
    Selection.Fields.Update
    Selection.GoTo What:=wdGoToBookmark, Name:="Start"
    With ActiveDocument.Bookmarks
    End With
    Dialogs(wdDialogFilePrint).Show
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to Update TOC/Print (2000/SP3)

    Are you sure your TOC is getting selected before you update the selection? If not, any reason you can't update all fields in the document (if any link to remote resources it could be slow...)? That would be the most reliable way to have the TOC update...

    I also think you could delete a few lines that don't seem to have any effect:

    <pre>Sub FilePrint()
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:="Start"
    End With
    Selection.GoTo What:=wdGoToBookmark, Name:="TOC" 'Does this select the TOC?
    Selection.Fields.Update
    With ActiveDocument.Bookmarks
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With
    Selection.GoTo What:=wdGoToBookmark, Name:="Start"
    Dialogs(wdDialogFilePrint).Show
    End Sub</pre>


  3. #3
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Wisconsin, USA
    Posts
    193
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Macro to Update TOC/Print (2000/SP3)

    Thanks for the reply. I'm assuming the TOC is selected because I can briefly see that it is selected then it jumps back to the print dialog screen. I'm guessing that because of the 2 different options for updating a TOC that it isn't working correctly. As far as updating entire document, there will be a letter with form fields in it that aren't to be updated.

    Also, thanks for removing unneeded lines - I had been doing that but have recorded and re-recorded so many times that I didn't clean it before posting.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Macro to Update TOC/Print (2000/SP3)

    To update just the page numbers in the TOC, use

    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs

    To update the entire TOC, use

    ActiveDocument.TablesOfContents(1).Update

    This assumes that you have only one TOC in the document. No need to set bookmarks and to change the selection.

  5. #5
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Wisconsin, USA
    Posts
    193
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Macro to Update TOC/Print (2000/SP3)

    Thanks Hans, works like a charm! I should have posted a couple of hours earlier.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •