none
Hyperlink on Userform to Jump to another Control. RRS feed

  • Question

  • Hi,

    I want to create Hyperlink on Userform to setfocus to textbox on the same userform or another userform, when I click on that.

    I have used the following code, but its not working.

    Private Sub Label1_Click()
    Link = UserForm1.TextBox1.SetFocus
        On Error GoTo NoCanDo
        ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
        Unload Me
        Exit Sub
    NoCanDo:
        MsgBox "Cannot open " & Link
    End Sub

    Any help on this will be appreciated.

    Friday, March 22, 2013 2:13 PM

Answers

  • Assuming textbox1 has a valid hyperlink string:

    Private Sub Label1_Click()
    Dim Link As String
    Link = UserForm1.TextBox1.Value
        On Error GoTo NoCanDo
        ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
        Unload Me
        Exit Sub
    NoCanDo:
        MsgBox "Cannot open " & Link
    End Sub


    Friday, March 22, 2013 2:35 PM
  • > Assuming textbox1 has a valid hyperlink string:

    Link needs to look like  "http://social.msdn.microsoft.com"

    So "Test" needs to be a valid address. Is "Test" a named range on a sheet? If it is, then use

    Application.Goto Link

    in place of

    ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True


    Saturday, March 23, 2013 12:49 PM
  • You can use this too:

    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
    
    sub run_link
    ShellExecute 0, "open", "http://" & textbox1.text , "", "", 0
    end sub


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Monday, March 25, 2013 8:05 PM
    Answerer

All replies

  • Assuming textbox1 has a valid hyperlink string:

    Private Sub Label1_Click()
    Dim Link As String
    Link = UserForm1.TextBox1.Value
        On Error GoTo NoCanDo
        ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
        Unload Me
        Exit Sub
    NoCanDo:
        MsgBox "Cannot open " & Link
    End Sub


    Friday, March 22, 2013 2:35 PM
  • Hi Bernie,

    Thanks for your reply.

    I have input "Test" in textbox1

    its giving me error "Cannot Open Test"

    Saturday, March 23, 2013 7:55 AM
  • > Assuming textbox1 has a valid hyperlink string:

    Link needs to look like  "http://social.msdn.microsoft.com"

    So "Test" needs to be a valid address. Is "Test" a named range on a sheet? If it is, then use

    Application.Goto Link

    in place of

    ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True


    Saturday, March 23, 2013 12:49 PM
  • You can use this too:

    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
    
    sub run_link
    ShellExecute 0, "open", "http://" & textbox1.text , "", "", 0
    end sub


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Monday, March 25, 2013 8:05 PM
    Answerer