Cell A1:
=HYPERLINK("#Sheet2!a2","link")
Sheet->View Code
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox ("hello")
End Sub
MessageBox does not open when I left click on A1; instead, #Sheet2!a2 opens. To further complicate matters,
Sheet->View Code
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
MsgBox ("hello")
End Sub
Right clicking on the cell with the hyperlink does fire the message box, but google fires anyway.
Sheet->View Code
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
MsgBox ("hello")
End Sub
Now double clicking A1 does not generate a message box.
Why?
Well that's a new one on me, but in both 2003 and 2010 the FollowHyperlink event is not fired for cells that contain the HYPERLINK() function. Both versions fire for native hyperlinks.
It looks like the SelectionChange event fires, so you could test that there's a hyperlink in the cell or whatever other tests you need.
来源:https://stackoverflow.com/questions/9828260/worksheet-followhyperlink-and-msgbox-not-working-in-excel-2010