简体   繁体   中英

Running Excel Macro On Hyperlink Click

I'm trying to assign macros to hyperlinks I have set up in excel. I have the hyperlinks linking back to the same cell that contains the hyperlink. Based on code examples I've found I've come up with this code block:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Select Case Target.Range.Address

Case "$B$3"
     MsgBox ("Test")
Case "$Z$3"
     MsgBox ("Test")
Case Else
    Exit Sub
End Select

End Sub

Nothing is happening when I click either hyperlink. I have tried running Application.EnableEvents = True as well and still can't get anything to fire. Also, I have verified the code block is set in the correct worksheet module. Any help would be appreciated. Thanks!

EDIT: Here is a screencap of the hyperlink dialog as an example for the hyperlinks I have set up:

http://i.imgur.com/QwHuXJJ.jpg

I have tried both "Z3" and $Z$3 for the address (both ways direct me to the cell properly, it just doesn't fire the macro.)

Your code works if the code is in the worksheet code area

Right-click the tab at the bottom and:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM