Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Feb 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding hyperlinks in office 2002 (2002 (XP) SP3)

    In office 2000, I recorded a macro to find hyperlinks in text I import from web documents. When found, the macro removed the link and converted the text to "normal". I used this many times and it worked well.
    Now I am using 2002 and the macro crashes. Debugging shows "Selection.Range.Hyperlinks(1).Delete" error. Additionally, if you try to FIND a hyperlink in a document, word says there no hyperlinks even though you can see them and they work (if you are online).

    The strange thing is, if I create a hyperlink in the same document, then with either FIND or running the macro, everything works properly and THAT hyperlink is removed - all the others remain.

    So, word 2002 is finding hyperlinks that I create but not the imported hyperlinks. Word 2000 did not do this.

    Any ideas?

    thanks

    Allan

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

    Re: Finding hyperlinks in office 2002 (2002 (XP) SP3)

    Could you attach an example? I just tried your line of code on some text with hyperlinks that I pasted from a web page into Word 2002 SP3, and it worked as intended.

  3. #3
    Lounger
    Join Date
    Feb 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding hyperlinks in office 2002 (2002 (XP) S

    Hi

    Here is my macro. I created it by recording keystrokes.

    Sub RemoveHyperlink()
    '
    ' RemoveHyperlink Macro
    ' Macro recorded 28/12/2006 by Allan Brown
    '
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Range.Hyperlinks(1).Delete
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    CommandBars("Stop Recording").Visible = False
    End Sub

    I have tried this several times now with imported web pages, the most recient being Woody's newsletter.

    As I said, this worked well with word 2000.

    I tried your macro that you posted some time ago and it works on the same document where mine did not. However, the text is still blue underlined and not "normal"

    The problem seems to be that word 2002 is not finding the imported hyperlinks while it does find the ones I create.

    thanks

    Allan

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

    Re: Finding hyperlinks in office 2002 (2002 (XP) S

    I think the problem is that a hyperlink pasted from another application (such as your browser) is not necessarily formatted with the Hyperlink style. Hyperlinks you create in Word itself are automatically formatted with that style.

    Try this code, it loops backwards through the collection of hyperlinks in the document, removes character formatting and deletes the hyperlink.

    Sub RemoveHyperlinks()
    Dim i As Integer
    For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
    With ActiveDocument.Hyperlinks(i)
    .Range.Font.Reset
    .Delete
    End With
    Next i
    End Sub

  5. #5
    Lounger
    Join Date
    Feb 2005
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding hyperlinks in office 2002 (2002 (XP) S

    Hi

    This works. Thank you.

    I wonder what the differences between office 2000 and 2002 are to cause this? When I installed 2002, I used my 2000 normal.dot template. Every other macro and button that are part of the template seem to work.

    Any way, thanks for your help

    Allan

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

    Re: Finding hyperlinks in office 2002 (2002 (XP) S

    I'm afraid I don't know the cause - I never used Word 2000 (I jumped from Word 97 to Word 2002 and 2003).

Posting Permissions

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