Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, I was wondering if you could help me with another Word problem.
    I've been searching the internet for a macro to use in Word that will locate all URLs in a document and turn them into hyperlinks.
    In order to break the links in my word document to an excel sheet, I also break the URL links. So I need to link these URLs again, they don't need to have any fancy anchor text, just the URL itself.
    Is there a way to do this with a macro?
    Thanks in advance.

    Using MS Word 2007 on XP.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Are the URLs complete, i.e. are they all of the form http://... or will http:// be missing from some or all of them?

  3. #3
    New Lounger
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    They are complete, they look like this:

    http://www.example.org

    And just want them to have that same anchor text, but be hyperlinks.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try this; it uses AutoFormat.

    Note: I have tested it in Word 2002; I don't have 2007.

    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

  5. #5
    New Lounger
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You rule so hard my friend.
    Thanks.
    However, this macro deletes the line breaks above and below the URLs. Is there any way to stop this from happening?

Posting Permissions

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