Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Tallahassee, Florida, USA
    Posts
    901
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add field code switch programatically (Word 2002)

    Background:
    We have a body of documents from a practice group which added cross references to paragraphs by using bookmarks of text. Those reference fields look like { REF bookmark h }. During our conversion we are preserving the references by locking the fields and moving the bookmarks to the beginning of the paragraphs. These documents will be numbered using heading numbers. Once numbered, I need to add the "n" switch to the ref fields and then unlock them so that the fields will read as { REF bookmark h n }.

    Because this group does a great deal of copying/pasting between documents, and all their documents use the same bookmark naming it is advantageous to facilitate keeping the references because it allows for more portability between documents.

    Question:
    Although I can use a For / Next statement to unlock the fields en masse, I was wondering if there is a way, short of doing a find/replace to add the n to the existing fields.
    Karen

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add field code switch programatically (Word 20

    What about something like this for starters:
    <pre>Sub AddNSwitchToRefFields()
    Dim fld As Field
    Dim doc As Document
    Set doc = ActiveDocument
    For Each fld In doc.Fields
    If fld.Type = wdFieldRef Then
    If InStrRev(fld.Code, "n") = 0 Then
    fld.Code.Text = fld.Code.Text + " n"
    End If
    End If
    Next fld
    End Sub
    </pre>


  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add field code switch programatically (Word 20

    need to also check for r and w, in case those are used.

  4. #4
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Tallahassee, Florida, USA
    Posts
    901
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add field code switch programatically (Word 20

    Thank you, Andrew! That certainly does the trick.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Karen

  5. #5
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Tallahassee, Florida, USA
    Posts
    901
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add field code switch programatically (Word 20

    Hi, Howard. Thanks for the added input and I'll keep it tucked away for future reference. However, because of the structure of pre-migration documents there the r and w do not currently exist in these fields and adding them would create more clean-up for the end-users.

    Thanks again!
    Karen

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add field code switch programatically (Word 20

    I did not suggest adding the r amd w, only that the code check for their existence to assure that none had slipped in.
    You may get unexpected results adding a n to a field that already has a r or a w.

Posting Permissions

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