2012-04-17 26 views
6

Microsoft Access 2003からオートメーションを使用して、Internet Explorer 9を制御してデータベースデータを使用してフォームを完成しようとしています。VBA入力イベントを伴うInternet Explorerオートメーション

入力は、データを検証して保存ボタンを表示させるイベントをブラウザで起動します。 sendkeysを使用すると、イベントがトリガーされます。しかし、私は非常に信頼性の低いsendkeysを見つけました。要素の値を変更して.fireevent( "onchange")を使用すると、何も起こりません。エラーでもありません。

私の質問は、どのようにイベントを発生させるかです。または、どのようにjavascriptが動作しているかを知ることができます。 IEのためのアドインのデバッグタイプは、どのイベントが起動されたかを教えてくれますか?もしそうなら、スクリプトを自分で実行できますか?

私のコードは以下の通りです。

Set IE = CreateObject("internetexplorer.application") 
IE.Visible = True 
IE.Navigate "https://extranet.website.com/Planning/Edition/Periodic?language=en" 

Do While IE.ReadyState <> 4 Or IE.Busy = True 
    DoEvents 
Loop 


'log in 
If IE.Document.Title = "website- access" Then 
    IE.Document.getElementById("login_uid").Value = "username" 
    IE.Document.getElementById("login_pwd").Value = "password" 
    IE.Document.all("ButSubmit").Click 
    Do While IE.ReadyState <> 4 Or IE.Busy = True 
     DoEvents 
    Loop 
End If 

Do While Not RstAvailability.EOF 
    StartDate = RstAvailability!AvailDate 
    IE.Document.getElementById("periodStart").Value = Format(StartDate, "dd mmm yy") 
    IE.Document.getElementById("periodEnd").Value = Format(StartDate, "dd mmm yy") 
    Set LinkCollection = IE.Document.GetElementsByTagName("A") 
    For Each link In LinkCollection 
     If link.innertext = "Add" Then 
      link.Click 
      Exit For 
     End If 
    Next 
    Do While IE.ReadyState <> 4 Or IE.Busy = True 
     DoEvents 
    Loop 


    Set objRows = IE.Document.GetElementsByTagName("tr") 
    If RstAvailability!RoomType = "DTW" Then 
     n = 0 
     While n < objRows.Length 
      If Trim(objRows(n).Cells(0).innertext) = "Single Room" Then 
       For i = 1 To 7 
        'objRows(n).FireEvent ("onchange") 
        'objRows(n).Cells(i).GetElementsByTagName("input")(0).Focus 
        'SendKeys Format(RstAvailability!roomcount - RstAvailability!RoomsSold, "0") & "{TAB}" 
        objRows(n).Cells(i).GetElementsByTagName("input")(0).Value = Format(RstAvailability!roomcount - RstAvailability!RoomsSold, "0") 
        objRows(n).Cells(i).GetElementsByTagName("input")(0).fireevent ("onchange") 
        Do While IE.ReadyState <> 4 Or IE.Busy = True 
         DoEvents 
        Loop 
       Next i 
      End If 
      n = n + 1 
     Wend 
    End If 

    Set objButtons = IE.Document.getelementsbyname("savePlanning") 
    objButtons(0).Click 

    Do While IE.ReadyState <> 4 Or IE.Busy = True 
     DoEvents 
    Loop 

    newtime = Now + TimeValue("0:00:10") 
    Do While True 
     If Now > newtime Then Exit Do 
    Loop 

    RstAvailability.MoveNext 
Loop 

入力フィールドのHTMLは、次のとおり

<tr class="first" roomId="30494" articleId="0" type="Availability" readonly="False"> 

<div> 

    <span class="roomName"> 

    Single Room 

    </span> 



</div> 

<span class="data"> 

<input id="Availabilities" name="Availabilities" type="text" value="" /> 

</span> 

<span class="data"> 

<input id="Availabilities" name="Availabilities" type="text" value="" /> 
回の

</span> 

ありがとう!

答えて

12

これを数日間にわたって発汗させた後の答えは、実際には非常にシンプルですが、MSDN上のドキュメントやWeb上の他の場所ではほとんど見つけられませんでした。

入力フィールドの値を変更する前に、ネットでそのフィールドにフォーカスを設定します。値を変更したら、別のフィールドにフォーカスを設定する必要があります。どうやら、イベントは焦点の喪失に襲われます。したがって、コードは次のようになります。

 n = 0 
    While n < objRows.Length 
     If Trim(objRows(n).Cells(0).innertext) = "Family Room" Then 
      For i = 1 To 7 
       objRows(n).Cells(i).GetElementsByTagName("input")(0).Focus 
       objRows(n).Cells(i).GetElementsByTagName("input")(0).Value = Format(RstAvailability!roomcount - RstAvailability!RoomsSold, "0") 
      Next i 
      objRows(n).Cells(1).GetElementsByTagName("input")(0).Focus 

     End If 
     n = n + 1 
    Wend 

私は、これはIE9のアクセシビリティに関するいくつかのMSDNのドキュメントを見て、見つけた方法を。それは障害者のための焦点を設定することについて助言していました。私はちょうど私がこれを試してみると思って、それは働いた。私はこれが他の誰かを助けることを望む。デイブ

+0

乾杯 – BlueTrin

1

あなたは右ライン「次のI」の前に次の行を入れて(IE9に)したい場合は

。フォーカスを失っていなくても動作するはずです。

objRows(N).Cells(I).GetElementsByTagName( "入力")私のために役立ちました(0).Click

関連する問題