How to programmatically edit all hyperlinks in a Word document?
22,935
Dim doc As Document
Dim link, i
'Loop through all open documents.
For Each doc In Application.Documents
'Loop through all hyperlinks.
For i = 1 To doc.Hyperlinks.Count
'If the hyperlink matches.
If LCase(doc.Hyperlinks(i).Address) = "http://www.yahoo.com/" Then
'Change the links address.
doc.Hyperlinks(i).Address = "http://www.google.com/"
'Change the links display text if desired.
doc.Hyperlinks(i).TextToDisplay = "Changed to Google"
End If
Next
Next
Here is a link to all the Hyperlink Methods and Properties
Author by
jinsungy
Engineering Manager with Full-Stack Development experience in .NET, MS SQL Server.
Updated on July 04, 2020Comments
-
jinsungy almost 4 years
Is there a macro, VBA code or VBScript that I can write to edit the urls of all the hyperlinks in my Word document? Either Word 97-2003 or docx format.
-
Roy Calderon about 8 yearsThis doesn't work with images with hyperlinks =/ Do you know how to get those?