Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Windows (http://www.go4expert.com/forums/windows-forum/)
-   -   Macro to convert URLs to Hyperlinks in MS Word (http://www.go4expert.com/forums/macro-convert-urls-hyperlinks-ms-word-t15899/)

Jette 22Jan2009 10:42

Macro to convert URLs to Hyperlinks in MS Word
 
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?

johnfewell 11Jun2009 03:37

Re: Macro to convert URLs to Hyperlinks in MS Word
 
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



All times are GMT +5.5. The time now is 18:54.