How do I edit the hyperlink in a word document through VBA

I have a word document that I use to mail merge from MSACCESS. A word in the document is hyperlinked to other document. I want to edit this hyperlink based on a value in a form in access. How do I do this through VBA.

NB: I'd prefer not to have to generate the entire word document from VBA. Just be able to change the hyperlink
LVL 16
Who is Participating?
Here is a start:
Sub ChangeHyperLInk()
     Dim wdApp As Word.Application
     Dim wdDoc As Word.Document
     Dim Hyp As Word.Hyperlink
     On Error Resume Next 'supress error checking
     Set wdApp = GetObject(, "Word.Application")
     On Error GoTo 0 'restart error checking
     If wdApp Is Nothing Then
         Set wdApp = CreateObject("Word.Application")
     End If
     wdApp.Visible = True
     Set wdDoc = wdApp.Documents("C:\MyFolder\MyFile.Doc")
     Set Hyp = wdDoc.Hyperlinks(1)
     Hyp.Address = "C:\Folder2\Doc1.doc"
     Hyp.TextToDisplay = "Document 1"
End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.