Add hyperlinks to directories in Word

brncao

Board Regular
Joined
Apr 28, 2015
Messages
149
I have a Word document with lots of directories in it (i.e. C:\abc\def\ghi) and I would like to be able to click on it to take me there.

Is there a macro that will find "C:\*" and convert it as a hyperlink?

1. Find "C:"
2. Highlight text to the right of it including "C:" until it hits a paragraph mark (I assume paragraph mark signals it is the end of the directory path). Just in case, trim any trailing spaces before the paragraph mark before converting it as a hyperlink.
3. Copy selection.
4. Add hyperlink based on selected text.
5. Repeat steps 1-4 throughout the document.

For some reason this forum is removing the backslashes from my post after "C:" but just assume it's there.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "C:\\[!^13]{1,}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    i = i + 1
    .Hyperlinks.Add .Duplicate, .Text, "", , .Text
    .End = .Hyperlinks(1).Range.End
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
MsgBox i & " hyperlinks added."
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,794
Messages
6,174,641
Members
452,575
Latest member
Fstick546

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