简体   繁体   English

在超链接上运行Excel宏单击

[英]Running Excel Macro On Hyperlink Click

I'm trying to assign macros to hyperlinks I have set up in excel. 我正在尝试将宏分配给我在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. 我也尝试过运行Application.EnableEvents = True ,但仍然无法执行任何操作。 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.) 我已经尝试使用“ Z3”和$ Z $ 3作为地址(两种方式都将我正确定向到单元格,只是它不会触发宏。)

Your code works if the code is in the worksheet code area 如果代码在工作表代码区域中,则您的代码有效

Right-click the tab at the bottom and: 右键单击底部的选项卡,然后:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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