View Full Version : Solved: Call Macro From Hyperlink
tonyrosen
11-21-2005, 01:49 PM
How would I go about calling a macro (MyMacro) via a hyperlink in my workbook (on the same sheet)?
Ken Puls
11-21-2005, 03:50 PM
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?
Shazam
11-21-2005, 07:30 PM
Here is a sample:
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
tonyrosen
11-22-2005, 06:59 AM
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!
tonyrosen
11-22-2005, 07:26 AM
I Ended up using this:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Not Intersect(Target.Parent, Range("C9")) Is Nothing Then
MySub
End If
End Sub
brunces
04-03-2006, 06:30 PM
tonyrosen,
You could also try this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("C9")) Is Nothing Then
MyMacro
End If
End Sub
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.