2013-03-06 15 views
5

私がcorrecet IDタグであると思った後に、検索ボックスにテキストを入力する際に​​問題があります。私はページのソースコードからIDを得ました。これまで他のウェブサイトでこれを行ってきました。誰かが私を助けてくれますか?これを行う別の方法がありますか?VBA - IE GetElementByIDが機能しない

Sub FileUpload() 

Dim IEexp as Object 
IEexp.visible = True 
IEexp.Navigate ("www.example.com") 

'this is where the problem 
IEexp.Document.GetElementByID("step1_id_bean_newSupportingDoc_description").Value _ 
= "monthly update" 

End Sub 

私はからIDを引っ張っ

ソースコード "呼び出されたオブジェクトがそのクライアントから切断されましたオートメーションエラー" を取得:

<td class="Label">Description</td> 
    <td class="Data"><input type="text" name="bean.newSupportingDoc.description" size="60" maxlength="250" value="" id="step1_id_bean_newSupportingDoc_description" class="NoBorder"/> 
</td> 
+2

入力要素にアクセスする前にドキュメントが読み込まれるのを待っていますか? –

+0

私はローカルで実行し、ページロードイベントが発生するのを待って、iwebbrowser2エラーを受け取ります。 – user1902540

+0

はい、私はページが完全に読み込まれるまで待つので、ブレークモードで実行しました。 –

答えて

0

あなたは

Do Until IEexp.readyState = 4 
DoEvents 
Loop 



IEexp.Document.getElementById("username").Value = "Monthly update" 


IEexp.Document.getElementById("password").Value = FilePth 
を試すことができますが
0

コードは機能します。 「保護モード」はどうですか?この記事を参照してください。http://www.sevenforums.com/tutorials/63141-internet-explorer-protected-mode-turn-off.html。 IEブラウザが保護モードで実行されている場合は、IEブラウザをオフにしてコードを再実行してください。

' Add References: 
' - Microsoft HTML Object Library 
' - Microsoft Internet Controls 

Sub FileUpload() 

    Dim IEexp As InternetExplorer 
    Set IEexp = New InternetExplorer 
    IEexp.Visible = True 
    IEexp.navigate "www.example.com" 

    Do While IEexp.readyState <> 4: DoEvents: Loop 

    Dim inputElement As HTMLInputElement 
    Set inputElement = IEexp.Document.getElementById("step1_id_bean_newSupportingDoc_description") 

    If (Not inputElement Is Nothing) Then 
     inputElement.Value = "monthly update" 
    Else 
     MsgBox "Input element not found on web page." 
    End If 

    IEexp.Quit 
    Set IEexp = Nothing 
End Sub 
1

Set IEexp = New InternetExplorerMediumを使用する場合は、インターネットオプションの設定を変更する必要はありません。これは、Medium Integrityアプリケーション設定でIEオブジェクトを自動的にインスタンス化します。

関連する問題