あなたが設定することができjs- WithEventsを実装するシンプルなクラスを使用してVBA間の通信を行い、ホストされたHTMLページ内の要素へのVBA参照をフックアップします。
以下の例を実行すると、HTMLテキストボックスを編集してからクリックすると(onchange
イベントが発生します)、入力にリンクされたクラスフィールドを介してVBAメッセージボックスがトリガーされます。
ローカルページとjsで問題を解決する方法を知るには、Googleの「ウェブのマーク」。埋め込みブラウザ制御wb1
とユーザーフォームで
Option Explicit
Private WithEvents txt As MSHTML.HTMLInputElement
Public Sub SetText(el)
Set txt = el
End Sub
Private Function txt_onchange() As Boolean
MsgBox "changed: " & txt.value
End Function
:クラスモジュールclsHtmlText
で
Option Explicit
Dim o As clsHtmlText '<< instance of our "withEvents" class
Private Sub UserForm_Activate()
Dim el As MSHTML.HTMLInputElement
With Me.wb1
.Navigate "about:blank"
WaitFor wb1
.Document.Open "text/html"
'or you can load a page from a URL/file
'Note: local pages need "mark of the web" in the markup
.Document.write "<html><input type='text' size=10 id='txtHere'></html>"
.Document.Close
WaitFor wb1
Set el = .Document.getelementbyId("txtHere")
Set o = New clsHtmlText
o.SetText el '<< assign the textbox so we can monitor for change events
End With
End Sub
'utility sub to ensure page is loaded and ready
Sub WaitFor(IE)
Do While IE.ReadyState < 4 Or IE.Busy
DoEvents
Loop
End Sub
https://stackoverflow.com/questions/7388391/detect-event-on- ie-visio/7410092#7410092 –