hyperlink in a UserForm for Word

H

h.de.vries060

How can I make a hyperlink (for email) on a UserForm made
with VBA for Word? I don't kwow what object the UerForm is.
 
J

Jay Freedman

You don't need to know what object the UserForm is...

You can put a label on the UserForm, name it lblLink, set its caption
to the email address, and format it like a link (blue, underlined).

Then put this code into the UserForm (courtesy of Karl Peterson's
sample at http://www.mvps.org/vb/code/HyperJmp.zip):

Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal _
lpDirectory As String, ByVal nShowCmd _
As Long) As Long

Public Function HyperJump(ByVal URL As String) As Long
HyperJump = ShellExecute(0&, vbNullString, URL, _
vbNullString, vbNullString, vbNormalFocus)
End Function

Private Sub lblLink_Click()
Call HyperJump(lblLink.Caption)
End Sub

When the user clicks the label, the URL will be launched. If it's a
"mailto" address, your email application will start a new message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top