Is it possible to add hyperlinks in a user form to link to different word documents for mail merging. I can get the docs to open through option buttons but non of the mail merge works correctly so need a more standard approach.
I created a userform and inserted labels that I underlined to give the appearance of a hyperlink.
Behind each label i placed the necessary code to open the word document, rather than hyperlinking.
Additional code ensured that the mail merge function was made "live" as such
Private Sub Label1_Click()
Dim wdApp As Word.Application
Dim WordWasNotRunning As Boolean
Dim wdDoc As Word.Document
'Get existing instance of Word if it's open; otherwise create a new one
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = New Word.Application
WordWasNotRunning = True
End If
wdApp.Visible = True
wdApp.Activate
Dim t
t = "template name.dot"
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\user\Desktop\myFolder\Fails To Attend")
Ah, so it really has nothing to do with hyperlinks, although of course going to a hyperlink will open the document.
BTW: I am not sure a userform can be called a "window".
For the sake of your own ability to scan through the code, you may want to reconsider keeping default names like Label1. Label1, by itself gives no indication of what file you are opening with it. If I understand correctly, each label will open a different document.
Also, this certainly works, but as it sort of hard codes the documents to open (by using labels), if you want to expand the possibilities, you may want to consider a combobox listing the applicable documents. That way it can be more dynamic.
Finally, you are declaring t, and setting it, but it does not appear to be used. What is this for?
In any case, thank you for posting what you came up with.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.