Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically edit all hyperlinks in a Word document?

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.

like image 384
jinsungy Avatar asked Jul 28 '10 16:07

jinsungy


People also ask

How do you automate hyperlinks in Word?

Open the document for which you want to set a hyperlink base. On the File menu, click Properties, and then click the Summary tab. In the Hyperlink base box, type the path that you want to use for all the hyperlinks that you create in this document. Click OK.


1 Answers

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

like image 102
Tester101 Avatar answered Sep 21 '22 18:09

Tester101