Excel中,ThisAddIn.vb:为什么不Application.SheetFollowHyp

2019-08-08 15:12发布

我试图发现在Excel中点击的超链接。 该Application.SheetFollowHyperlink事件声称 ,这将被称为“当您单击Microsoft Excel中的任何链接。”

然而,尽管它确实火灾当单元格中包含像一个网址www.google.com ,它不是当单元格包含不=HYPERLINK("http://www.google.com", "google")

如何检测点击第二类型的超链接?


例如,一个简单的Excel中添加:

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

当您单击含有细胞会出现含有“超链接被点击的”一个消息框, www.google.com ,但不包含电池=HYPERLINK("http://www.google.com", "google")

Answer 1:

我似乎已经解决了这个问题,尽管我不知道为什么下面的作品,而我上面使用的代码不会:

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


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