Excel, ThisAddIn.vb: why Application.SheetFollowHyperlink is not called for = HYPERLINK ()

I am trying to detect hyperlink with a hyperlink in Excel. The Application.SheetFollowHyperlink event claims that it will be called "when any hyperlink in Microsoft Excel is clicked".

However, although it fires when the cell contains a URL such as www.google.com , this does not happen when the cell contains =HYPERLINK("http://www.google.com", "google") .

How to determine clicks for the second type of hyperlink?


For example, a simple excel adds:

 Public Class ThisAddIn Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup End Sub Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub Private Sub Application_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Microsoft.Office.Interop.Excel.Hyperlink) Handles Application.SheetFollowHyperlink MsgBox("Hyperlink Clicked") End Sub 

A window will appear with the message "Hyperlink clicked" when you click on the cell containing www.google.com but not the cell containing =HYPERLINK("http://www.google.com", "google") .

0
source share
1 answer

I seem to have solved the problem, although I'm not sure why the following works, and the code I used above does not work:

 Private HyperlinkFollower As Excel.DocEvents_FollowHyperlinkEventHandler Private Sub CalledWhenHyperlinkClicked(ByVal Target As Excel.Hyperlink) Dim w As Microsoft.Office.Interop.Excel.Window = Globals.ThisAddIn.Application.ActiveWindow MsgBox("hyperlink clicked") End Sub EventDel_HyperlinkFollower = New Excel.DocEvents_FollowHyperlinkEventHandler(AddressOf CalledWhenHyperlinkClicked) AddHandler worksheet.FollowHyperlink, EventDel_HyperlinkFollower 
0
source

All Articles