Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hyperlink to a UserForm

    Hi,

    I have a data table that is created through VBA by copying from another sheet using Advanced Filter. As the table populates based on sort criteria, I am looking to be able to generate a Hyperlink on the "Name" field that once clicked will open a user form. Is this possible to do?

    Any help would be appreciated.

    JS

  2. #2
    New Lounger
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the sample code in my worksheet module:

    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    If Not Intersect(Target.Parent, Range("K47:K54")) Is Nothing Then
    UserForm1.Show
    End If
    End Sub

    What would need to go into the individual cell on the worksheet to properly call this sub?

    Thanks for any help.

    JS

  3. #3
    New Lounger
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Updated - I am looking to open a userform from a hyperlink on a worksheet. Here is where i am currently at in the process:

    In the Standard Module:

    'Add Hyperlink to each name in the name column
    Dim linkRange As Range
    Set linkRange = sortWS.Range("M48:M" & sortLastRow)
    sortWS.Hyperlinks.Add linkRange, ThisWorkbook.Name, "More_Info", "Patient Detailed Information"

    In the Standard Module:

    Sub More_Info()
    UserForm2.Show
    End Sub

    In the ThisWorkbook Module:

    Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, _
    ByVal Target As Hyperlink)
    Application.Run Target.SubAddress
    End Sub

    This code successfully adds a hyperlink to each of the cell contents in "linkRange" and once the text in the hyperlinked cell is clicked, UserForm2 is displayed..., However, the code then hangs in Sub More_Info() method and opens the VBA window.

    If I am operating the worksheet, and click on a Hyperlink, the VBA developer window opens, then UserForm2 opens and sits and waits for me to close UserForm2. I close UserForm2 and it takes me to the VBA window with the cursor on the code line UserForm2.Show

    Can someone help me try to get this working properly and display the userform normally without opening the VBA window and appearing to just "sit" stalled out...?

    Thank you for any help

    JS

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    I would have the hyperlinks link to the same cell they are in and use the followhyperlink code you had originally.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    New Lounger
    Join Date
    May 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks i changed to that and worked fine

Posting Permissions

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