replace all filenames with hyperlinks

R

Richard

I need to update a macro that finds the first filename with a hyperlink (to
that file) so that the macro makes this replacement for all filenames in the
document.


Note: all my filnames begin with "\\ERD", are followed with a "|", and are
preceeded with "_"

Sub AddHyperlinks2Docs()
Dim myRange As Range
Dim i As Long
Dim y As Long
Dim oHpl As Hyperlink
Set oRng = ActiveDocument.Range
ActiveDocument.Range(0, 0).Select
With oRng.Find
.Text = "_\\ERD"
.Wrap = wdFindStop

If .Execute Then
i = oRng.End
oRng.Collapse direction:=wdCollapseEnd
.Text = "|"
y = Len(.Text) + 1
If .Execute Then
oRng.Select
Set myRange = oRng.Duplicate
myRange.Start = i - 5
myRange.End = oRng.End - y
tmptext = myRange.Text
Debug.Print tmptext
Set oHpl = ActiveDocument.Hyperlinks.Add(myRange, Address:=tmptext,
TextToDisplay:=tmptext)

End If
End If

End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top