Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I add hyperlinks in user form to open word documents

Status
Not open for further replies.

2ks

Technical User
Jan 13, 2007
54
GB
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.

Many thanks
 
I have a macro button that opens a VBA user form window.

Within that window I would like a list of all the letter choices that the user can select. On selection the appropriate word document loads
 
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")

wdDoc.Activate

ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\user\Desktop\my Folder\list.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documents and Settings\user\Desktop\myFolder\list.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Dat" _
, SQLStatement:="SELECT * FROM `AMF$_FilterDatabase`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess

End Sub
 
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.

Gerry
My paintings and sculpture
 
And I'd replace all ActiveDocument references to wdDoc ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top