Consulting

Results 1 to 4 of 4

Thread: Userform hyperlink

  1. #1
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location

    Question Userform hyperlink

    Hello all,

    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?

    Thanks.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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

  3. #3
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location

    More complex...

    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"
    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
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  4. #4
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    ...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 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
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •