PDA

View Full Version : [SOLVED:] Userform hyperlink



Zack Barresse
06-07-2004, 04:08 PM
Hello all, :006:

I'm working on a User Form at work, and can't seem to make heads or tails of a correct syntax. In my User Form I've got an image, it's my company logo. What I'm trying to do is link a left-mouse click on the logo as a hyperlink to their web site.

My brain is fried (and it's still only Monday!), could anyone point my aching head in the right direction? :confused:

Thanks.

Jacob Hilderbrand
06-07-2004, 05:06 PM
Hey Firefytr

Try this

Put the hyperlink somewhere in the workbook then.


Private Sub Image1_Click()
Sheets("Sheet1").Range("D9").Hyperlinks(1).Follow NewWindow:=False, _
AddHistory:=True
End Sub

Scottie P
06-07-2004, 05:18 PM
but I am not sure where you're going with the project so I will post anyway.

You'll want to insert a Standard Module and paste in this code
Be sure to change the url line to the address of your choosing.



Option Explicit
Public 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 Const SW_SHOWNORMAL = 1
'change URL here
Public Const Site1 As String = "http://www.vbaexpress.com/forum" (http://www.vbaexpress.com/forum"'change)
Sub myURL()
ShellExecute 0, "open", Site1 & vbNullChar, vbNullString, _
vbNullString, SW_SHOWNORMAL
End Sub

Next, we want to make sure that the Userform is ready so put these couple of lines in the image_click:


Private Sub image1_Click()
Call myURL
End Sub


That should do it for ya!!

X

Scottie P
06-07-2004, 05:42 PM
...and just to give an alternative to the "Call"...you can try this out - same basic build (this one will also allow for the use of other urls...note that there are parameters that you can change to further customize the outcome)
In a Standard Module:


Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
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
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Sub RunShellExecute(ByVal sFile As Variant)
Dim hWndDesk As Long
Dim success As Long
Const SE_ERR_NOASSOC = &H31
hWndDesk = GetDesktopWindow()
success = ShellExecute(hWndDesk, "Open", sFile, 0&, 0&, 3)
End Sub

Sub webpage1()
RunShellExecute http://www.vbaexpress.com/forum
End Sub

Sub webpage2()
RunShellExecute http://www.anywhere (http://www.anywhere/) you want to go.com
End Sub


and for the Userform:



Private Sub Image1_Click()
webpage1
End Sub

Private Sub Image2_Click()
webpage2
End Sub


Let me know how you manage.

X