1

私の要件は、WebページのリンクがクリックされたときにExcelで何らかのアクションを実行するために実行されるVBAコードがExcelに必要です。たとえば、Webページのリンク「ログイン」をクリックすると、VBAコードはキーボードのprintscreenボタンを押す必要がありますsendkeys を使用するように)。Google で 2 週間にわたってこのソリューションを探していましたが、取得できませんでした。これは緊急のプロジェクト要件です。時間を節約してください。よろしくお願いします。

4

2 に答える 2

1

この機能を有効にするために Internet Explorer 内でネイティブにできることはありません。

Excel オートメーションを実行する ActiveX コントロール (C#、C++、VB6 などを使用) を作成する必要があります。

いくつかの便利なリンク:

于 2012-10-25T14:12:36.160 に答える
1

これは、同様の質問 (http://stackoverflow.com/questions/12877872/possible-to-intercept-onchange-event/12927960#12927960) に対する回答の編集版です。

「Microsoft HTML オブジェクト ライブラリ」および「Microsoft インターネット コントロール」のプロジェクト参照セット

クラス モジュール「clsEvents」内:

Option Explicit

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

通常のモジュールでは:

Option Explicit

Dim evt As clsEvents

Sub Setup()

    Dim IE As New InternetExplorer
    Dim 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 el2 = IE.document.getElementsByTagName("a")(1)

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

End Sub

サブルーチンを実行しSetup、IE でページの「Javascript」リンクをクリックすると、VB エディタのイミディエイト ウィンドウに出力が表示されます。

始めるのに役立つことを願っています。

于 2012-10-25T23:09:18.627 に答える