Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hyperlink color (2000)

    Hi!

    I'm inserting cross-reference links in a document, and the client would like the link to be blue. When I insert the link I can assign formatting to make the link blue (either directly or by assigning a paragraph or character style), but it doesn't stick. When I update the document, the link text turns back to the default formatting.

    Other field codes use the * MERGEFORMAT switch. It seems like this is automatically done for REF fields. Is this true? Is there some way to make links stay a color that is different than the link target?

    Thanks,
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

  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: Hyperlink color (2000)

    Hi Bob:
    The * mergeformat switch should do it for you. If you select the cross reference field, apply a blue font to it (or the hyperlink character format), & add the * mergeformat switch, the link should remain that color. You can also color just the first letter of the field code (the R in REF) & use the * charformat switch to do the same thing.
    Hope this helps,

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink color (2000)

    Thanks Phil -

    That worked great. I guess I was thinking backwards about that switch or I would have tried it. It is also not documented anywhere that you can add that switch to this field. I guess it is a universal switch?

    Along those lines, do you know how I would add that switch programmatically? I'm actually building these fields in a macro, and the .InsertCrossReference method doesn't include a way to add that value to the field. I know that I can move the selection into the field code and "type" the text into the field, but is there a better way?

    I realize this is a bit off topic, and might be better posted in the VBA forum.

    Thanks!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

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

    Re: Hyperlink color (2000)

    Hi Bob,
    Sorry, but I'm not a VBA expert, so that's beyond my abilities. Perhaps one of the other experts will see this thread & be able to help.
    Cheers,

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

    Re: Hyperlink color (2000)

    I use Word 2002, so I don't know if this will work in Word 2000. Applying any kind of formatting to a cross reference automatically inserts /* MERGEFORMAT. So after inserting the cross reference, you can select it in code (it acts as one character), and apply the formatting you like.

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

    Re: Hyperlink color (2000)

    Hi Hans:
    In Word 2000, adding formatting to the REF field through the graphical interface will add the * Mergeformat switch. I haven't tried it through VBA.
    Cheers,

  7. #7
    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: Hyperlink color (2000)

    <P ID="edit" class=small>(Edited by jscher2000 on 19-Nov-03 19:55. Added programming note.)</P>Here's a code sample for modifying that field after inserting it. Due to the way the Insert Cross-Reference dialog works (it is persistent), you cannot capture its behavior easily and thereby wrap code like this around it. So... anyway, this gives you an idea of how to access the field's contents after it has been inserted. Note that you will need to change bmk1 (or insert such a bookmark) in order to test it.
    <pre>Sub InsertXRefAndMergeFormat()
    ' Recorded/edited 11/19/2003
    Dim intRngStart As Integer, rngTemp As Range
    ' Capture start of current selection for later use
    intRngStart = Selection.Start
    ' Insert X-ref (recorded from dialog)
    Selection.InsertCrossReference _
    ReferenceType:="Bookmark", _
    ReferenceKind:=wdContentText, _
    ReferenceItem:="bmk1", _
    InsertAsHyperlink:=True, _
    IncludePosition:=False
    ' Create a range over the part of the document that contains the REF
    Set rngTemp = ActiveDocument.Range(intRngStart, Selection.End)
    ' Insert the switch into the first (only) field in that range
    rngTemp.Fields(1).Code.Text = _
    rngTemp.Fields(1).Code.Text & "* MERGEFORMAT "
    ' Clean up objects
    Set rngTemp = Nothing
    End Sub</pre>

    Hope this helps.

    Programming Note: In many cases you could do something like the following, but it doesn't work with this method:

    Dim fld As Field
    Set fld = Selection.InsertCrossReference(etc.)

    Even though it inserts a field, the method does not return a reference to the field object, hence the need to fish it out of the document "manually" with the rngTemp.

  8. #8
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink color (2000)

    I tried it through VBA and it didn't work. As you found, Phil, it works manually, but the field is unchanged if you select it using code and apply the style.

    I also found that even if I apply the style manually, I get weird results when I change the target text. If I insert a reference to a heading paragraph (text is "Heading 3") and then apply blue formatting to the field, everything works fine. However, if I change the text of the heading (say, to "Another Heading 3") and update the link field, the words "Another Heading" stay blue, but the "3" turns black!

    I plan to do some more poking around--perhaps it is a problem with my document. I need to try it on a simpler test document and see if I can pin down what is happening. But, I've got a deadline to meet!

    Bob
    Writing Consultant / Word Template Designer
    Words Connect

  9. #9
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink color (2000)

    Thanks Jefferson -

    I tried your code sample and it worked. Thanks!

    I was trying to access the contents of the field code using .Fields(1).Code.Text, but I kept getting object errors. Perhaps I was doing it wrong. Now I can't recreate my errors.

    Bob
    Writing Consultant / Word Template Designer
    Words Connect

  10. #10
    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: Hyperlink color (2000)

    I "assumed" that after the insertion the insertion point would be just past the field. If the insertion point ends up somewhere else, errors are highly probable. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> But I didn't test enough scenarios to get errors. If you get more, please post back for everyone's reference.

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

    Re: Hyperlink color (2000)

    Hi Bob:
    I've never noticed that before, but you're abosolutely right. It seems that the hidden bookmark only covers the same number of words as the original, starting from the left. If you had three words in the middle of the heading after applying direct formatting to the field, & then update the field, the last 3 words do not have the direct formatting.

  12. #12
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink color (2000)

    Hi Phil -
    I hadn't realized it was tied to the length of the original bookmark text, but that makes sense with what I've seen. I couldn't find any way around this, other than to write a "refresh cross references" macro that my users can run when doing final print preparation.

    Thanks for your help!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

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

    Re: Hyperlink color (2000)

    Hi Bob:
    Well, at least you found a solution. Would you care to post the macro? I can see where it might come in handy.

  14. #14
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink color (2000)

    Here is the way I did it.


    Sub RefreshCrossReferenceLinks()
    ' Cycle through document and update link style on ref headings
    Dim objField
    Dim strStyle

    For Each objField In ActiveDocument.Fields ' cycle through fields
    If objField.Type = wdFieldRef Then ' check if REF field
    objField.Update
    objField.Select
    Selection.Collapse direction:=wdCollapseStart
    strStyle = Selection.Style ' get style from text preceding the field
    objField.Select
    Selection.Range.Style = strStyle
    End If
    Next
    End Sub


    A couple of caveats:

    * I am only refreshing REF fields. These seem to be the only ones that lose part of their formatting as we've discussed.

    * Once the target text has been changed, the field no longer returns the style I applied (a character style in my case). Instead, it returns the style of the entire paragraph. I have to collapse the selection to pick up the character style from the character preceding the field. In every case, the link should be preceded by an open quote ("), which retains the character style.

    Any comments would be welcome!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

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

    Re: Hyperlink color (2000)

    Hi Bob:
    Another way that might accomplish your purpose is to use the CharFormat switch instead of Mergeformat. Here's how can do this. When you're done editing the headings & cross-references:
    1. Display field codes (Alt+F9).
    2. Open Find/Replace (Ctrl+H).
    3. Find: Mergeformat
    Replace: Charformat
    4. Replace all & update fields.

    Unlike the * Mergeformat switch, the * charformat switch applies the direct or character style character formatting of the first letter of the field (the "R" in REF) to the entire field. Changing your headings will not affect this. I suppose that you could create a macro that would make the changes to the formatting switch & then update the fields.

    If you're inserting the REF fields using VBA, perhaps you could insert the * charformat switch to begin with. Then you wouldn't have to worry about quotes.

Page 1 of 2 12 LastLast

Posting Permissions

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