Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check URL without creating hyperlink (2003 SP2)

    I would like to create a macro that will take selected text as a URL and then open it in IE, but without creating hyperlinks in the text.

    As a rule, some of the URLs are completely formed, beginning with http://, https://, and sometimes ftp://, but if the URL starts with "www," the http:// is dropped. I simply need to verify that the URL given goes where the text says it goes -- and sometimes I'm dealing with a lot of URLs.

    I'd like to simply highlight the URL, click a macro button (or press a keyboard shortcut), and have IE go to the Web site as if I had just Ctrl-clicked a hyperlink in the text. I'm sure I'm missing something obvious here.

    Thanks.

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

    Re: Check URL without creating hyperlink (2003 SP2)

    Try this macro:

    Sub OpenURL()
    Dim strURL As String
    On Error GoTo ErrHandler
    strURL = Selection.Text
    If Not LCase(Left(strURL, 7)) = "http://" Then
    strURL = "http://" & strURL
    End If
    ActiveDocument.FollowHyperlink strURL
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    End Sub

    Assign it to a keyboard shortcut or custom toolbar button.

  3. #3
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check URL without creating hyperlink (2003 SP2)

    Thanks, Hans. This seems to work.

    It was the .FollowHyperlink that I was missing. I kept trying to see how Word connected to active hyperlinks for some clue, and that (obviously) didn't help...

    I altered your code a bit to account for URLs that start with https: and ftp: -- it seems to work just as well:
    <pre>Sub OpenURL()
    Dim strURL As String
    On Error GoTo ErrHandler
    strURL = Selection.Text
    If Left(strURL, 3) = "www" Then
    strURL = "http://" & strURL
    End If
    ActiveDocument.FollowHyperlink strURL
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    End Sub
    </pre>


    Thanks again.

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

    Re: Check URL without creating hyperlink (2003 SP2)

    Some web addresses don't start with www, for example support.microsoft.com, and some that do, don't require it, for example wopr.com will work just as well as www.wopr.com. If you want to take those into account too, you'd have to modify the code I posted by adding checks for "https://", "ftp://" and "file:///".

  5. #5
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check URL without creating hyperlink (2003 SP2)

    In the text that I work with, the only URLs that don't include the protocol at the beginning are ones that start with "www" (strange, I know, but it works). So with an address like support.microsoft.com, I would add the http:// to the URL before I checked it.

    So, for my purposes, the altered code works perfectly.
    Thanks.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    Renton, Washington, USA
    Posts
    12,560
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Re: Check URL without creating hyperlink (2003 SP2)

    In IE 7 when the HTTP is drop, IE thinks that it may be "PHISHING" and the page may be blocked. This is called "Forwarding" and is one of the steps that the phisher's use.

    Now running HP Pavilion a6528p, with Win7 64 Bit OS.

  7. #7
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check URL without creating hyperlink (2003 SP2)

    Dave,

    If this is the case, we might need to rethink our URL style as we put together a slew of new books about Vista and Office 2007. Do you have any links (preferably to the Microsoft site) that could elaborate on this a bit?

Posting Permissions

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