2017-08-02 1 views
0

SHDocVw.InternetExplorerを使用して、ローカルHTMLファイルをPowerPointに表示します。このファイルには送信ボタンが付いたフォームがあり、ボタンをクリックしたときにvba関数を実行したいと考えています。私はInternetExplorerのonQuitイベントを処理するために以下を行った。VBAでのHTMLElementイベントの処理

クラスモジュール "CIE"

Public WithEvents ie As SHDocVw.InternetExplorer 

Private Sub ie_onQuit() 
    Debug.Print "onQuit was fired" 
End Sub 

モジュールのコード

Option Explicit 

Public curCIE As CIE 

Sub open_ie() 
    Dim CIEobj As CIE 
    Set CIEobj = New CIE 

    Dim ie As SHDocVw.InternetExplorer 
    Set ie = New SHDocVw.InternetExplorer 

    ie.Visible = True 
    ie.Navigate "C:\search.html" 

    Do While ie.Busy Or ie.readyState <> 4 
     DoEvents 
    Loop 

    Set CIEobj.ie = ie 
    Set curCIE = CIEobj 
End Sub 

は、私が実際に

curCIE.ie.Document.getElementsByTagName("button").Item(0) 

のonclickイベントを処理したいが、私は続行するのか分かりません。

+0

は、いくつかの宣言IEの 'window'オブジェクト内の' App'変数を '.execScript'メソッド経由で呼び出し、Excelの' Application'オブジェクトへの参照を割り当て、次にIEボタン内の 'App.Run" MacroName "でExcelマクロを呼び出します。 [この例](https://stackoverflow.com/a/38134477/2165759)が役立ちます。 – omegastripes

答えて

2

次に、あなたのクラスモジュールはこの方法を作る、MSHTMLへの参照を追加することができます。

Public WithEvents ie As SHDocVw.InternetExplorer 

Private WithEvents button As MSHTML.HTMLButtonElement 

Public Sub LoadButton() 
    Set button = ie.document.getElementsByTagName("button").Item(0) 
End Sub 

Private Function button_onclick() As Boolean 
    'do what you want here 
End Function 

Private Sub ie_onQuit() 
    Debug.Print "onQuit was fired" 
End Sub 

そして、他のモジュールでは、CIEobj.ieプロパティを設定した後、このステートメントを追加:

CIEobj.LoadButton