IE11自动化:更改下拉列表的值

时间:2016-02-14 18:43:52

标签: excel vba excel-vba

我已经包含了用于导航到特定网站的代码;这里的最终游戏是尝试点击"下面的下拉列表"并选择一个选项,然后单击go。这对我来说是一次学习经历。我很想知道为什么?代码背后。

Sub internetautomation2()
    Dim IE As InternetExplorer      'Created Class of type InternetExplorer
    Set IE = New InternetExplorer   'Initiated Class, object IE created
                                    'Properties and methods of
                                    'Internet Explorer now usable

    IE.Top = 0                      'IE window properties Topleft corner  
    IE.width = 1500                 '1500pixels wide

    IE.Visible = True               

    IE.Navigate ("ibc.com")         'Navigate to particular website

    While IE.ReadyState = READYSTATE_LOADING    'Wait for website to load
        DoEvents
    Wend

   'Clicking drop down list,selecting option,click go

   End Sub

2 个答案:

答案 0 :(得分:0)

不确定这个问题与JavaScript有什么关系,只是将更改事件处理程序连接到列表并导航到列表值:

 Private Sub ComboBox1_Change()
   IE.Navigate (ComboBox1.Value)
 End Sub

答案 1 :(得分:0)

这应该这样做:

'Set to the secod option "Deposit express"
IE.Document.getElementById("ctl00_IBCOtherOnlineServices_ddlLoginTo").selectedIndex = 1
'click the submit button
IE.Document.getElementById("ctl00_IBCOtherOnlineServices_btnLoginTo").Click