Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Field Update woes

    I'm going insane. This makes absolutely no sense to me. The documents have a TOC and numerous cross references. When I run the following code as part of a Sub, all fields except the TOC update. If I run it as a standalone Sub, the TOC updates!

    For Each fldField In ActiveDocument.Fields
    fldField.Update
    Next

    Other things I have tried include referencing the index of the TOC field and updating it, but I'm running into version problems where the index of that field might a tad too dynamic. I have also tried looping through the storyranges and updating fields, but the same thing happens, every field but the TOC updates.

    Pulling my hair out,

    Chris

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Field Update woes

    Chris,

    Does this help?:

    ActiveDocument.TablesOfContents(1).Update

    Gary

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Field Update woes

    OK. Got it. The following works, but is mind-numbingly inelegant.

    'update fields
    For Each fldField In ActiveDocument.Fields
    fldField.Update
    Next

    'now loop through and update the insanely freakish TOC
    For Each fldField In ActiveDocument.Fields
    If fldField.Type = wdFieldTOC Then fldField.Update
    Next

    Feel like I'm taking a hammer to open an egg. Any other ideas that would make me feel better about myself?

    Thanks,

    Chris

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Field Update woes

    Gary,

    Perfect! Thanks. Any idea why the TOC is so recalcitrant? I'm very confused by that... I've run a For loop on the fields collection, a For loop through the stories, and a selectall and selection.fields.update. None of 'em worked all the time.

    Regards,

    Chris

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Field Update woes

    Is it because there are two-levels of fields? One pass to update them all, but the TOC field needs a second pass to obtain what's updated on the first?

    Chalres Kenyon put me onto "doing everything three times".

  6. #6
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Field Update woes

    Chris,

    Of course! Thanks. I really paid the stupid tax on this one. The code creates headings with x-refs to bookmarks. Of course, the For loop updates the TOC before it updates the x-refs in the headings.

    Doh!

    Chris

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Field Update woes

    If it works good, it is good.

Posting Permissions

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