Macro to convert URLs to Hyperlinks in MS Word

Discussion in 'Windows' started by Jette, Jan 22, 2009.

  1. Jette

    Jette New Member

    Joined:
    Jan 22, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I've been searching the internet for a macro to use in MS Word that will locate all URLs in a document and turn them into clickable hyperlinks. It seems my problem is the OPPOSITE of most peoples... I have found tons of macros designed to REMOVE hyperlinks!

    The problem with my document is it is already created, with over 1000 URLs that were pasted "special" as unformatted text from an excel document. Now I need to make all of those URLs into hyperlinks, without having to edit each one by hand! Is there a macro that will do this for me?
     
  2. johnfewell

    johnfewell New Member

    Joined:
    Jun 10, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I did not write this, sharing from another forum.
    This works if URLs are complete
    Makes the URL the anchor text of the hyperlink.


    Code:
    Sub URL2Hyperlink()
      Dim f1 As Boolean, f2 As Boolean, f3 As Boolean
      Dim f4 As Boolean, f5 As Boolean, f6 As Boolean
      Dim f7 As Boolean, f8 As Boolean, f9 As Boolean
      Dim f10 As Boolean
      With Options
        ' Save current AutoFormat settings
        f1 = .AutoFormatApplyHeadings
        f2 = .AutoFormatApplyLists
        f3 = .AutoFormatApplyBulletedLists
        f4 = .AutoFormatApplyOtherParas
        f5 = .AutoFormatReplaceQuotes
        f6 = .AutoFormatReplaceSymbols
        f7 = .AutoFormatReplaceOrdinals
        f8 = .AutoFormatReplaceFractions
        f9 = .AutoFormatReplacePlainTextEmphasis
        f10 = .AutoFormatReplaceHyperlinks
        ' Only convert URLs
        .AutoFormatApplyHeadings = False
        .AutoFormatApplyLists = False
        .AutoFormatApplyBulletedLists = False
        .AutoFormatApplyOtherParas = False
        .AutoFormatReplaceQuotes = False
        .AutoFormatReplaceSymbols = False
        .AutoFormatReplaceOrdinals = False
        .AutoFormatReplaceFractions = False
        .AutoFormatReplacePlainTextEmphasis = False
        .AutoFormatReplaceHyperlinks = True
        ' Perform AutoFormat
        ActiveDocument.Content.AutoFormat
        ' Restore original AutoFormat settings
        .AutoFormatApplyHeadings = f1
        .AutoFormatApplyLists = f2
        .AutoFormatApplyBulletedLists = f3
        .AutoFormatApplyOtherParas = f4
        .AutoFormatReplaceQuotes = f5
        .AutoFormatReplaceSymbols = f6
        .AutoFormatReplaceOrdinals = f7
        .AutoFormatReplaceFractions = f8
        .AutoFormatReplacePlainTextEmphasis = f9
        .AutoFormatReplaceHyperlinks = f10
      End With
    End Sub
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice