Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Restore the formatting of character-style format

    Word97SR2 et al. (Good ole Al!)

    How do I restore the blue-underlined formatting for the hyperlinks?


    I have a document with hyperlinks. They appear blue-underlined.

    I inadvertently remove the local formatting for the entire document (Ctrl-A, Ctrl-space).

    How do I restore the blue-underlined formatting for the hyperlinks?



    The hyperlinks are correctly styled with a character style, Hyperlink, which can be demonstrated in the original document by modifying that style.

    Modifying the style AFTER removing local formatting doesn't bring back the colour to my characters.


    Which prompts a more general question: How do I restore the formatting ANY character-style formatting that is inadvertently lost?

    I confess to a puzzlement. I had always preached (!) that the advantage of character-styles versus local-character formatting was its stability.

    See also properly format a document using character styles

  2. #2
    BAM
    Guest

    Re: Restore the formatting of character-style format

    Hi Chris,

    <Ctrl Space> resets the text to the Default Paragraph font. So effectively you removed the Character Style associated with the hyperlinks.

    Since these were hyperlinks, to get the character style back you can run a macro to remove the hyperlinks, then use Format/AutoFormat and add the hyperlinks back. Note that you would want to click the "Options" command and remove all AutoFormats with the exception of "Internet and network paths" before running the AutoFormat command.

    Here is a macro for unlinking the hyperlink fields:

    Sub UnlinkHyperlinks()
    Dim i As Long
    For i = 1 To ActiveDocument.Hyperlinks.Count
    ActiveDocument.Hyperlinks(1).Delete
    Next i
    End Sub

    To answer your question on how to restore a Character Style if it is inadvertently removed, unfortunately it is the same way you restore any Style that has been removed, it must be reapplied.
    ~~~~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Restore the formatting of character-style format

    Hi,

    As long as the hyperlinks are still hyperlinks, then the Hyperlink character style can be reapplied to them this way:

    <pre>Sub ReApplyHLinkCharStyle()
    Dim aHLink As Hyperlink
    For Each aHLink In ActiveDocument.Hyperlinks
    aHLink.Range.Style = "Hyperlink"
    Next aHLink
    End Sub
    </pre>

    BAM, the AutoFormat idea is interesting, and I tried it (even made a macro out of it), but it does some other odd things to my sample document (such as delete all empty paragraphs), so this may be a case of the cure being worse than the disease <g>.

    BTW, watch out for deleting members of a collection by looping through the collection with a counter: the code posted in your note will produce a runtime error:

    Suppose I start with 3 hyperlinks.
    ActiveDocument.Hyperlinks.Count evaluates to 3.
    In the first spin through the loop, hyperlink # 1 gets deleted, and in the second spin through the loop, hyperlink # 2 gets deleted.
    The third time through the loop, the loop is looking for ActiveDocument.Hyperlinks(3) - but there is only 1 hyperlink left in the document - which triggers an error message that the requested member of the collection doesn't exist.
    The other odd artifact with this approach is that if you have more than 2 or 3 members of the collection, after you run the macro (and acknowledge the error message), back in the document you'll see that the macro has left every second item untouched.

    The workaround for these situations is to loop through the collection backwards:
    For i = ActiveDocuments.Hyperlinks.Count To 1 Step -1

    Gary

  4. #4
    BAM
    Guest

    Re: Restore the formatting of character-style format

    Hi Gary,

    Good calls! I had forgotten about the AutoFormat removing empty paragraphs. I think it was Word 97 that automatically built this in to AutoFormat instead of making it another option as it was in Word 6 and I think Word 95.

    As for the macro, that was one I picked up from the newsgroups. Now that you mention it, I recall this being discussed and never updated it with the correct code. It's updated now though <img src=/S/grin.gif border=0 alt=grin width=15 height=15>. Thanks!
    ~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Restore the formatting of character-style format

    (snip!) CLIP-CLOP, Clip-Clop, clip-clop, .....

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Restore the formatting of character-style format

    Hi, BAM, and thanks.

    >Sub UnlinkHyperlinks()

    What this needs, he said craftily, is a front-end to locate all the character styles ACTUALLY IN USE and then an outer loop to undo Msoft's nefarious trick .......

Posting Permissions

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