Converting All Plain Text Links to Hyperlinks

kckay

Board Regular
Joined
Nov 8, 2010
Messages
134
I have an Excel workbook that we input data into. once complete I run a macro that performs a mailmerge and some formatting of the text including changing plain text link addresses to blue/underline. This process worked great as we were a hard-copy shop. Due to the coronavirus, we are converting to electronic letter. I need to convert the plain text link to an active and correct link. I was unable to get any code to work in an Excel macro against the Word document, so now call this macro (thank you Techkie007) in the Word template (.dotm):

VBA Code:
Sub Hyperlinker()
Dim Rng As Range

Set Rng = ActiveDocument.Range
With Rng.Find
    Do While .Execute(findText:="www.", Forward:=False) = True
    Rng.MoveEndUntil (" ")
        ActiveDocument.Hyperlinks.Add _
            Anchor:=Rng, _
            Address:=Rng.Text, _
            SubAddress:="", _
            ScreenTip:="", _
            TextToDisplay:=""
        Rng.Collapse wdCollapseStart
    Loop
End With

End Sub

This code does convert the plain text link to a hyperlink, but does so in the wrong information. It will place the full path directory of the Word document and append the link address into the hyperlink. For example: incorrect link is C:\this letter directory\wqcdcompliance.com where the correct link should be \wqcdcompliance.com.

How can I modify the code to only use the correct link?

Thank you for your assistance.

I did try:

VBA Code:
Sub Hyperlinker()
    Word.Options.AutoFormatReplaceHyperlinks = True
   Selection.Range.AutoFormat
End Sub

It reformatted a couple of headings and a couple of sentences in the body, but the hyperlinks were correct.
 
So where do the instructions say anything about "copy all of the text from the Excel cells" or "search the document for the 'plain text links'" or "replace the 'plain text link' with brackets and HYPERLINK and the correct hyperlink "??? have you actually done anything those instructions say to do??? At which point do you get stuck???
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top