Can a hyperlink call a macro?

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
See if this helps. Right click on your sheet tab holding the hyperlink, left click on View Code, and paste the following procedure into the large white area that is the worksheet module. Press Alt+Q to return to the worksheet.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox "Your macro goes here"
End Sub


A workbook-wide event for this can be placed in the workbook module if you want a macro to be run for any hyperlink clicked. The code that is

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
MsgBox "Your macro goes here"
End Sub


In either case, replace
MsgBox "Your macro goes here"
with whatever the essence of your macro code really is.
 

neonangel

Board Regular
Joined
Jul 5, 2004
Messages
99
Interesting. My only addition would be that you could make it hyperlink specific by conditioning (select case) on the Target parameter

Regards,

Alex
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
I'd be interested to see what you have in mind there, can you post an actual code example of that.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,804
Messages
5,598,151
Members
414,214
Latest member
marketingnumbersguy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top