2017-01-21 59 views
0

我想從網頁(http://www.debentures.com.br/exploreosnd/consultaadados/sndemumclique/)下載一些數據到Excel電子表格中。從網絡插入數據(VBA)時選擇下拉列表

加載此頁面後,我必須從「Códigodo Ativo」下拉列表中手動選擇一個選項,然後選擇「議程」。

有沒有辦法通過VBA自動完成它?

例如:從「Códigodo Ativo」下拉列表中選擇「RDVT11」,選擇「Agenda」,然後從表格中下載數據並顯示在頁面底部?

我到目前爲止宏:

Private Sub Agenda() 
Sheets("Dados").Select 

Dim ProductionAddress As String 
ProductionAddress = "http://www.debentures.com.br/exploreosnd/consultaadados/sndemumclique/x_pu_historico_r.aspx?" 

Dim ie As Object 
Set ie = CreateObject("InternetExplorer.Application") 
With ie 
    .Silent = True 
    .Visible = True 
    .Navigate ProductionAddress 
End With 

While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend 

ie.document.getElementByid("ctl00_ddlAti").Value = "RDVT11|11001110111100001" 

While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend 


Set objButton = ie.document.getElementByid("ctl00_x_agenda_r") 
    objButton.Focus 
    objButton.Click 
While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend 

ie.Quit 
Set ie = Nothing 
End Sub 

回答

0

您需要捕獲時下拉被激活瀏覽器發送請求。打開Chrome開發工具並觀看網絡選項卡。你會看到一個POST請求sndemumclique/。這將有一些標題和表單數據。你的代碼將需要基本上覆制這個請求。有可能的話,並非所有的頭文件和表單域都是必需的,但沒有嘗試就無法知道。

+0

我添加了一些代碼,我對這個問題做出了...如果你可以看看它,我真的很感激... –

+0

我得到它加載「Códigodo Ativo」,然後點擊「議程」。我現在唯一缺少的是:如何將頁面底部顯示的表格中的數據下載到電子表格中?你能幫我嗎,格里沙?非常感謝! –

+0

我發佈了我的代碼到目前爲止。它進入頁面。插入「Códigodo Ativo」並點擊「議程」。現在,我無法將表格下載到電子表格中(表格名稱爲「ctl00_ContentPlaceHolder1_C_agenda_r1_grdAgenda」。 您認爲您可以幫助我嗎? –