HTML中控件事件非常简单,可以直接写在document事件里,比如:Option ExplicitDim WithEvents doc As HTMLDocumentPrivate Function doc_onclick() As Boolean Dim objButton As IHTMLElement
On Error Resume Next doc_onclick = True Set objButton = doc.parentWindow.event.srcElement If LCase(objButton.tagName) <> "input" Then Exit Function If LCase(objButton.Type) <> "button" Then Exit Function If Err.Number <> 0 Then Exit Function
Debug.Print "按钮" & objButton.Value & "被点击了" End FunctionPrivate Sub Form_Load() Me.WebBrowser1.Navigate2 "e:/temp.html" End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If Not pDisp Is Me.WebBrowser1.Object Then Exit Sub
http://www.vbforums.com/showthread.php?t=372811
Dim objButton As IHTMLElement
On Error Resume Next
doc_onclick = True
Set objButton = doc.parentWindow.event.srcElement
If LCase(objButton.tagName) <> "input" Then Exit Function
If LCase(objButton.Type) <> "button" Then Exit Function
If Err.Number <> 0 Then Exit Function
Debug.Print "按钮" & objButton.Value & "被点击了"
End FunctionPrivate Sub Form_Load()
Me.WebBrowser1.Navigate2 "e:/temp.html"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If Not pDisp Is Me.WebBrowser1.Object Then Exit Sub
Set doc = Me.WebBrowser1.document
End Sub