Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Update TOC automatically after open (Word 2003 (SP2))

    I have a user manual which displays the TOC differently upon opening depending on the user. For two of our staff the TOC shows the first link to page 1-1, which is correct. For the other two staff members the page displays as 1-2, and their TOC must be updated for it to display 1-1. We are going to send the Word file to our customer and want to ensure that she does not have to update the TOC herself. I wrote a small macro to update all fields and called it AutoOpen. When opening the file from one of the affected computers, the macro appears to run fine, a message appears on the status bar saying that all fields are being updated, but the TOC still displays page 1-2. Is there a better way to automate this, and what is the user setting that is causing this discrepancy?

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

    Re: Update TOC automatically after open (Word 2003 (SP2))

    If the TOC has been updated before saving the document, it should look the same to anyone who opens it, as far as I know. Without seeing the document, it's hard to say why the TOC displays different results.

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

    Re: Update TOC automatically after open (Word 2003 (SP2))

    BTW, you could use this line to update page numbers in the TOC (assuming you have only one TOC in the document):

    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs

  4. #4
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC automatically after open (Word 2003 (SP2))

    Another small thing to consider: Although 2003 seems to allow more control than XP, your printer settings can also affect the pagination/TOC. Specifically, if your printer options are set to print Hidden text, that text will be "counted" towards the page lengths, and can affect the resulting page numbers. Likewise, if the document's compatibility options include "Use printer metrics to lay out document," (Tools: Options > Compatibility) , a workstation's default printer can change the pagination (since the line lengths and heights are determined by the printer's built-in fonts rather than by the metrics of the TrueType fonts.)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Update TOC automatically after open (Word 2003 (SP2))

    Thanks, Hans. Your one line of code to update the TOC worked and I prefer it to the macro I recorded.
    Nobody here has any idea why the document appears differently to different people, either.

  6. #6
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    McLean, VA
    Posts
    125
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Update TOC automatically after open (Word 2003 (SP2))

    No compatibility options were selected on the affected computer I tested.
    I don't think the printer settings are set to Hidden Text, but how do I check that?

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

    Re: Update TOC automatically after open (Word 2003 (SP2))

    In the Print tab of Tools | Options...

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Ephrata, Washington, USA
    Posts
    683
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC automatically after open (Word 2003 (SP2))

    I would like to use this code in a template I am having problems with. It sounds like it may solve my issue. When we save the template, the page numbers in the TOC are fine. But when you use the template (File, New, template on my computer..), the page numbers all show as page 2 until the user right-clicks and updates the TOC. This doesn't happen in other templates, but it does in this one. I understand this is a bug of some kind. Microsoft's site said not to use Print Layout, but that is the default view for everyone and I don't think we will get people to change it for just one document. So, I would like the TOC to update automatically. But, I have not idea how to use this code. Where do I put it? I know how to get to the code screen, but after that I'm lost. Do I create a macro? Thanks for your help!!

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

    Re: Update TOC automatically after open (Word 2003 (SP2))

    Open the template.
    Select Tools | Macro | Visual Basic Editor... or press Alt+F11.
    Look for your template in the Project Explorer on the left hand side.
    If necessary, expand it until you see ThisDocument under Microsoft Word Objects.
    Double click ThisDocument.
    Copy and paste the following code into the module that appears:
    <code>
    Private Sub Document_New()
    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs
    End Sub
    </code>
    This code will be executed each time you create a new document from the template. If you also want to run the code automatically each time a document based on the template is opened, add the following code below the code you already have:
    <code>
    Private Sub Document_Open()
    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs
    End Sub</code>

Posting Permissions

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