2016-09-09 5 views
0

私はウェブサイトから回答をコピーしようとしていますが、ページを更新できるようにドロップダウンリストからオプションの1つを選択する必要があります。Excel VBAオプションWebサイトのドロップダウンリストとクリックを選択

これまでのところ、私はIEを開いてドロップダウンボタンをクリックすることができましたが、その理由を知らないオプションを選択することはできません。以下のコードのサンプルをご覧ください。

Sub OpenWebSelectClickSaveHtmlFile() 
    Dim URL As String 
    URL = "http://formulaacademia.com.br/academia" 
    Set myIE = CreateObject("InternetExplorer.Application") 
    With myIE 
     .navigate URL 
     .Visible = True 
     Do While .Busy = True Or .readyState <> 4 
     Loop 
     DoEvents 
     Set selectitems = myIE.document.getElementsByTagName("button") 
     For Each i In selectitems 
      i.Click 
     Next i 
    End With 
End Sub 

RGDS

+0

'DoEvents'を' Do ... Loop'の中に置きます。最終的に回答から取り出す予定のデータは何ですか? IEの代わりにXHRを使用する方が良い解決策かもしれません。 – omegastripes

答えて

0

それはこのようなものでなければなりません。ニーズに合わせて関連部品を変更してください。

Sub passValueToComboBox1() 
    Dim ie As Object 
    Dim oHTML_Element As IHTMLElement 

    Set ie = CreateObject("InternetExplorer.Application") 
    ie.Visible = True 
    ie.navigate "http://peterschleif.bplaced.net/excel/combobox/index.php" 
    While ie.Busy Or ie.readyState <> 4: DoEvents: Wend 

    Set oHTML_Element = ie.document.getElementsByName("selectedReportClass")(0) 
    If Not oHTML_Element Is Nothing Then oHTML_Element.Value = "com.db.moap.report.FUBU7" 

    For Each oHTML_Element In ie.document.getElementsByTagName("input") 
     If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For 
    Next 
End Sub 
関連する問題