View Single Post
 
Old 10-19-2019, 08:11 AM
Jazz43 Jazz43 is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Oct 2009
Posts: 54
Jazz43 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You can't have hyperlinks in a text file, but you can in a Word document. Assuming that you example is a fair representation call the following macro from a loop to open your documents
Code:
Sub AddLinks(oDoc As Document)
Dim oPara As Paragraph
Dim oRng As Range
Dim vPara As Variant
Dim strLink As String
Dim strDisplay As String
Dim lngPara As Long

    For Each oPara In oDoc.Paragraphs
        Set oRng = oPara.Range
        oRng.End = oRng.End - 1
        If InStr(1, oRng.Text, "C:\") > 1 Then
            vPara = Split(oRng.Text, Chr(34))
            strDisplay = Trim(vPara(0))
            strLink = Trim(Replace(vPara(1), Chr(34), ""))
            oRng.Text = ""
            oRng.Hyperlinks.Add Anchor:=oRng, Address:=strLink, TextToDisplay:=strDisplay
        End If
    Next oPara
lbl_Exit:
    Set oPara = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
Thank you very much for the quick answer but I would not know how to call the macro with a loop, I tried to use the code by changing
Sub AddLinks(oDoc As Document) to:
Code:
Sub AddLinks()
Dim oDoc As Document
....
But it didn't work, so how can i use your code?
Reply With Quote