First time learning VBA. I want to write a VBA script to add a hyperlink to each line of a range of selected paragraphs in word 2016. The hyperlink would open a document with the filename matching the line of text selected and are stored in the same folder.
Here what I found and put together but I can't get it to compile. please help.
Sub Test()
'
Dim arr
' Put text of Word's selection to the array
arr = Split(Selection.Range, vbCr)
' Show dimension of array
Debug.Print "LBound = " & LBound(arr), "UBound = " & UBound(arr)
' Show each element of array
For i = 0 To UBound(arr)
'select the line
ActiveDocument.Selection.arr(i) unit:=wdLine, Extend:=wdExtend
ActiveDocument.Hyperlinks.Add Anchor:= arr(i) Address:=arr(i) _
, SubAddress:="", ScreenTip:="", TextToDisplay:=arr(i)
Next
End Sub
Here what I found and put together but I can't get it to compile. please help.
Sub Test()
'
Dim arr
' Put text of Word's selection to the array
arr = Split(Selection.Range, vbCr)
' Show dimension of array
Debug.Print "LBound = " & LBound(arr), "UBound = " & UBound(arr)
' Show each element of array
For i = 0 To UBound(arr)
'select the line
ActiveDocument.Selection.arr(i) unit:=wdLine, Extend:=wdExtend
ActiveDocument.Hyperlinks.Add Anchor:= arr(i) Address:=arr(i) _
, SubAddress:="", ScreenTip:="", TextToDisplay:=arr(i)
Next
End Sub