Consulting

Results 1 to 6 of 6

Thread: Solved: Call Macro From Hyperlink

  1. #1

    Solved: Call Macro From Hyperlink

    How would I go about calling a macro (MyMacro) via a hyperlink in my workbook (on the same sheet)?

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Can I ask why you'd want to run a macro from a hyperlink? The standard methods would be from a forms button, activex button, change event, menu item or toolbar button...

    Anything special about hyperlink that you'd prefer it that way?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Here is a sample:



    [VBA]
    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

    Select Case Target.Parent

    Case "Sheet3!A1"

    Call MyMacro1

    Case "Sheet3!A2"

    Call MyMacro2

    End Select
    End Sub
    [/VBA]

  4. #4
    kpuls,

    the "standard" around this place is to use Hyperlinks, not buttons. From a button is the only way I've done it. Hence, I have no clue how to from a Hyperlink.

    Shazam,

    SHAZAAM!

  5. #5
    I Ended up using this:


    [VBA]
    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    If Not Intersect(Target.Parent, Range("C9")) Is Nothing Then
    MySub
    End If
    End Sub
    [/VBA]

  6. #6
    VBAX Regular
    Joined
    Mar 2005
    Posts
    50
    Location
    tonyrosen,

    You could also try this:

    [vba]

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("C9")) Is Nothing Then
    MyMacro
    End If
    End Sub
    [/vba]

    Worked fine for me.

    -----

    Ken Puls,

    I once needed something like this as well. I had a file full of sheets and macros. The first sheet had a "menu" with plenty of buttons. Some of these buttons simply called sheets and cells, but others called macros. Then I decided to get rid of those buttons and use hyperlinks only, so that my menu would have a cleaner and smoother layout (buttons took much space). That's when I realized I couldn't call macros from hyperlinks. So I had to use something like the above code to get my hyperlinks working with macros.

    -----

    Hugs, fellas!

    Bruno
    Last edited by brunces; 04-03-2006 at 06:49 PM.

Posting Permissions

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