Results 1 to 9 of 9
  1. #1
    N7DR
    Guest

    CHARFORMAT in Word 2000; is it broken?

    I have the following snippet of code from a Word97 macro:

    With Selection
    .Style = ActiveDocument.Styles("Hyperlink")
    .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
    Text:="REF " + temp + "h * CHARFORMAT", PreserveFormatting:=False
    End With

    What this used to do (in Word97) is to create a field entry with the
    text contained in the string variable 'temp', formatted as a hyperlink
    (i.e., blue with blue underline) and also with the hyperlink property
    so that if clicked, I jumped to the bookmark.

    Using exactly the same code in Word2000 gives a somewhat different
    result. Namely, although it still functions as a hyperlink, the
    distinctive hyperlink formatting is NOT applied.

    I have two questions that maybe someone can help with:

    1. WHY does the code not do the right thing any more? The Word2000
    documentation implies that it should. It says that the style of the
    "R" in "REF" will be applied to the result of evaluating the field
    code. According to the VBA snippet, that "R" should be rendered in the
    hyperlink style and therefore the field should display in that style
    -- which is, of course, exactly what happens when Word97 runs the
    macro.

    2. WHAT do I need to change to get the result that I used to get in
    Word97?

    The interesting thing is that if I take my Word2000 document and open
    it in Word97 -- without any changes -- suddenly I get all my fields
    appearing with the correct (hyperlink) style.

    Doc Evans

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CHARFORMAT in Word 2000; is it broken?

    Hi,

    You can put in a hyperlink with the following method:

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="http://www.wopr.com/", _
    SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Text

    That will show up as blue.

    I'm not familiar with CHARFORMAT, I'm sorry, I can't help you with that.

    Geoff
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #3
    N7DR
    Guest

    Re: CHARFORMAT in Word 2000; is it broken?

    Thanks for replying.

    Your suggestion works fine for hyperlinks, but the purpose of the macro is to put *cross-references* in the hyperlink style. If there's some way to adapt the Address field to refer to a cross reference instead of a URL, that would (perhaps) work, but I don't think one can do that, can one? (If so, what would the format of the Address parameter be?) Just for background, I vaguely remember trying to do the job this way at some point, but could never get it to accept a cross-reference instead of a URL in the Address parameter.

    I reluctantly came to the conclusion that the CHARFORMAT method is the only way to get cross-references to appear in the hyperlink style; I'd be very happy to be proved wrong.

    Like I say, the macro worked fine in Word 97 though, and the Help in Word 2000 certainly strongly implies that the macro should work unchanged in Word 2000 (in fact, I think that the Help wording in this area is identical in the two versions of Word.)

    Doc Evans

  5. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CHARFORMAT in Word 2000; is it broken?

    Doc,

    OK, now I can see where you're coming from.

    It does seem strange. Even when I try to manually format the hyperlink, it doesn't show the colour blue or the underline. It can display any other colour I try to change it to, or a stronger underline, but when I change it back to blue, it disappears.

    You can try this for an approximation after creating the link:

    .Font.Underline = wdUnderlineThick
    .Font.Color = RGB(0, 0, 254)

    (the ".font.color" is almost but not quite blue. If I change it to RGB(0,0,255) the colour disappears again.

    Geoff
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #5
    N7DR
    Guest

    Re: CHARFORMAT in Word 2000; is it broken?

    I think I tried this too (perhaps six months ago, when I first discovered the problem) -- but I only went so far as to discover that I couldn't apply the hyperlink style successfully (oddly, it appears to think that it's in the hyperlink style; but, as you say, there's no evidence of that on the screen). I had not gone the extra step that you went, to discover that slightly changing the style would enable at least something approximating hyperlink style to be displayed.

    It's all very strange. It's as if the mere style name "hyperlink" is doing something. I think I'll try playing some more -- perhaps make a "hackhyperlink" style that is identical to "hyperlink" and see if that displays properly. If it doesn't, then I'll try setting the colour of "hackhyperlink" to (0, 0, 254) and removing the underline (which I can probably do without at a pinch).

    Sure seems like all this is the result of a bug of some sort in Word 2000. Is there some way to report this to Microsoft? I tried wandering around their support site and everything I came across sort of implied that if I was having a problem it couldn't possibly be a bug and I needed to spend money to get the "solution". I tried posting to the public Microsoft newsgroup for VBA problems, but that produced no response of any kind.

    Doc Evans

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

    Re: CHARFORMAT in Word 2000; is it broken?

    I think this is what you are looking for.

    <pre> Dim strTemp As String
    strTemp = "stuff"


    With selection
    .EndKey unit:=wdStory, Extend:=wdMove
    .InsertParagraph
    .Collapse direction:=wdCollapseEnd
    .Text = strTemp & " iz hear"
    .Bookmarks.Add Name:=strTemp, Range:=.Range
    .Collapse direction:=wdCollapseEnd
    .InsertParagraph
    .Collapse direction:=wdCollapseEnd
    .InsertParagraph
    .Collapse direction:=wdCollapseEnd
    .InsertParagraph

    .Fields.Add Range:=selection.Range, Type:=wdFieldRef, _
    Text:=strTemp, PreserveFormatting:=True
    .PreviousField.Select

    End With

    ActiveDocument.Hyperlinks.Add Anchor:=selection.Range, Address:="", _
    SubAddress:=strTemp, ScreenTip:="", TextToDisplay:=selection.Text
    </pre>


  8. #7
    N7DR
    Guest

    Re: CHARFORMAT in Word 2000; is it broken?

    Well, I don't pretend to understand any of that code -- all the stuff about inserting paragraphs, collapsing, "iz hear" [????] etc. seems really weird and utterly unlike anything I've ever seen before. As far as I can make out, the name of the bookmark to which the the link points goes into strTemp; is that right?

    I'll try it and let you know how it goes -- if it works then I'll make an effort to understand it :-)

    Thanks very much,
    Doc Evans

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

    Re: CHARFORMAT in Word 2000; is it broken?

    Put the code in a macro and run it on a document.
    It creates its own target, just for testing. Some of the code is just for running a test.

    If the result is what you wanted, then run the macro again, stepping thru the code, to see what it does.

    You can check each of the statements in the online Help.

    You'll learn a lot by analyzing the code.

  10. #9
    N7DR
    Guest

    Re: CHARFORMAT in Word 2000; is it broken?

    YES! This seems to work! So, even though I don't understand why the other method doesn't work (I maintain that it _ought_ to work, given the documentation and the history of it working in W97) I'll have a shot at incorporating your code instead.

    I'm not sure how easy it's going to be to replace my current code with the new code (there are several hundred places where the mechanism is used, and I'm not sure if there's a single "global" way to make the substitution (e.g., by simply replacing the macro with your code under the same macro name) or whether I have to find every instance and force the new code to be re-executed.

    Anyway, I'll play with it and see how it goes.

    Once again, THANK YOU VERY MUCH!

    Doc Evans

    PS Urgh! I just tried to convert the test document to PDF and Distiller blew up on me. But that's not a particularly unusual occurrance (Adobe seems to have been taking beta-testing lessons from Miscrosoft recently; their newest version of FrameMaker isn't anything like as stable as prior versions either). Probably it will convert just fine next time I try. Thanks again.

Posting Permissions

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