Vba 是否可能拦截onchange事件?

Vba 是否可能拦截onchange事件?,vba,Vba,在VBA中,是否可以截获javascript onchange事件并获取webbrowser控件中的原始ID <select name="status0" id="status0" onchange="javascriptonchangeeventhere"> 上面的代码是一个combobox演示,如果我从combobox中选择一个项目,它将在javascript中处理onchange。它所做的是调出一个包含当前日期和参考号的表单,相反,我想调出我自己的userform,然后将数据

在VBA中,是否可以截获javascript onchange事件并获取webbrowser控件中的原始ID

<select name="status0" id="status0" onchange="javascriptonchangeeventhere">

上面的代码是一个combobox演示,如果我从combobox中选择一个项目,它将在javascript中处理onchange。它所做的是调出一个包含当前日期和参考号的表单,相反,我想调出我自己的userform,然后将数据放入一个相关的notes0字段。当它发生时,我如何截取它,以便将其分配到正确的字段。

下面是一个简短的示例。为Microsoft HTML对象库和Microsoft internet控件设置的项目引用

在类模块clsEvents中:

Option Explicit

Public WithEvents slct As MSHTML.HTMLSelectElement
Public WithEvents href As MSHTML.HTMLAnchorElement

'Note that having defined "href" as "WithEvents", if you choose "href"
'  from the left-hand dropdown at the top of the class code module
'  then the right-hand dropdown will populate with events you can select
'  from to create an event-handling procedure in the class

Private Function href_onclick() As Boolean
    Debug.Print "link clicked"
    href_onclick = False 'cancels the navigation
End Function

Private Sub slct_onchange()
    Debug.Print "select onchange - value is " & slct.Value
End Sub

Private Function slct_onclick() As Boolean
    Debug.Print "select onclick - value is " & slct.Value
End Function
在常规模块中:

Option Explicit

Dim evt As clsEvents

Sub Setup()

    Dim IE As New InternetExplorer
    Dim el As Object, el2 As Object

    Set evt = New clsEvents

    IE.Visible = True
    IE.navigate "http://www.csee.wvu.edu/~riggs/html/select_example.html"

    Do While IE.Busy
    Loop

    Set el = IE.document.getElementsByTagName("select")(1)
    Set el2 = IE.document.getElementsByTagName("a")(1)

    If Not el Is Nothing Then
        Debug.Print "setting event capture: currentvalue=" & el.Value
        Set evt.slct = el
    End If

    If Not el2 Is Nothing Then
        Debug.Print "setting event capture on link:" & el2.innerText
        Set evt.href = el2
    End If

End Sub
如果您运行Setup子命令,然后更改第二个select的值,或者单击IE页面上的Javascript链接,您应该会在VB编辑器的即时窗口中看到输出


希望这能帮助您开始。

没有切实可行的方法吗?或者甚至确定onchange事件发生的位置?