Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set Field Results in Stone (Word 2003)

    I work for a U.S. State Legislature and need to preserve the text of various field codes at the point when a draft is filed as a proposed bill [law].

    I can toggle fieldcodes so that they don't show but I would like to insure they can never be changed and just get rid of the field code entirely. I can't find a VBA statement to do this.

    Thanks for your help
    Bob

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Field Results in Stone (Word 2003)

    Hi Bob:
    Just select all the fields (Ctrl+A) & unlink them (Ctrl+Shift+F9). Of course, they can always be changed by the next legislature. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Cheers,

  3. #3
    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: Set Field Results in Stone (Word 2003)

    The unintuitive word is unlink. This will convert the field code from being a field code to being the result displayed by the field, whether it is text (e.g., a DATE or INCLUDETEXT field) or a picture (e.g., an EMBED PBrush or INCLUDEPICTURE field). You may be able to record the syntax with the macro recorder and the key combination Ctrl+Shift+F9.

    Note #1: There also is the concept of locking the field so that it won't automatically update. However, someone later could unlock and update the field.

    Note #2: When you unlink a Table of Contents fields, the hyperlinks may be destroyed. I'm sure it has happened to me in the past, and I'm not sure how it works nowadays.

    Note #3: As with any of the many collections in the Word object model, when you unlink a field, you remove it from the collection; it is no longer a field, the collection is one member smaller. For this reason, if you plan to loop through all of them, it may be safest to countdown backwards. In other words:
    <pre>Sub UnlinkAllFields()
    Dim intCount As Integer
    With ActiveDocument.Fields
    For intCount = .Count To 1 Step -1
    .Item(intCount).Unlink
    Next
    End With
    End Sub
    </pre>

    Hope this helps.

    Added: Actually, if you aren't trying to check and skip over the fields, you can do it all in one go with ActiveDocument.Fields.Unlink

  4. #4
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Field Results in Stone (Word 2003)

    Thanks Phil & ischer. I knew there had to be a way.
    The line "ActiveDocument.Fields.Unlink" seems to be exactly what I was looking for.

    Thank you
    Bob

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Set Field Results in Stone (Word 2003)

    This command will only unlink fields in the main story. If you have any fields in the header or footer, or in text boxes then you need to step through those too, Probably the best way to do this is
    <code>
    Sub UnlinkAllFields()
    Dim rngStory As Range

    For Each rngStory In ActiveDocument.StoryRanges
    rngStory.Fields.Unlink
    Next rngStory

    End Sub
    </code>

    StuartR

    PS. Whilst testing the above I discovered that you can put fields in comments, I'd never tried that before!

  6. #6
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set Field Results in Stone (Word 2003)

    Thanks Stuart. I used your Sub and it appears to be working just fine.

    Bob

Posting Permissions

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