0

我正在尝试检测 Excel 中单击的超链接。Application.SheetFollowHyperlink 事件声称“当您单击 Microsoft Excel 中的任何超链接时”将调用它。

然而,尽管当单元格包含类似 url 时它会触发,但当www.google.com单元格包含=HYPERLINK("http://www.google.com", "google").

如何检测对第二种超链接的点击?


例如,一个简单的excel add in:

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").

4

1 回答 1

0

我似乎已经解决了这个问题,虽然我不确定为什么下面的代码有效,而我上面使用的代码没有:

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
于 2013-02-01T19:50:54.153 回答