Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post

    Replace Refs to bookmark with Refs to doc property (Word 2003)

    I need to replace a bunch of bookmarks with custom document properties, so users can update the reusable text bits more easily and reliably without using macros. They kept deleting the bookmarks.

    Has someone already written a macro that goes through a doc, finds each REF field that references a bookmark and replaces it with a reference to a custom document property? I already have a set of custom document properties that have the same names are the corresponding bookmarks.

    I may have been searching for the wrong thing, but searching the forums didn't turn up anything I could use.

    Thanks,

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

    Re: Replace Refs to bookmark with Refs to doc property (Word 2003)

    Try this:
    <code>
    Sub ChangeRefs()
    ActiveWindow.View.ShowFieldCodes = True
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = " REF "
    .Replacement.ClearFormatting
    .Replacement.Text = " DOCPROPERTY "
    .Execute Replace:=wdReplaceAll
    End With
    ActiveWindow.View.ShowFieldCodes = False
    ActiveDocument.Fields.Update
    End Sub</code>

  3. #3
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Replace Refs to bookmark with Refs to doc property (Word 2003)

    Thanks. Who would have thought something so direct and simple would work?

    The only catch is the cases where I inserted the REF fields as hyperlinks. The /h after the bookmark name doesn't make sense for a document property.

    So I need to go through and remove the /h switches first. I'll go check to see if there are other instances of "/h" that need to stay. If not, I'll use something similar to zap all of them, then rerun the macro you suggested.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Replace Refs to bookmark with Refs to doc property (Word 2003)

    Hi Jessica,

    Something to be aware of is that Hans' code wonít catch any PAGEREF fields, which in any event canít be changed to a DOCPROPERTY equivalent.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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