這裏是導入用IE自動化數據的代碼。
輸入參數
開始日期(在Sheet按照下面的截圖輸入)= B3
結束日期= B4
Şirketler= B5(它允許哪些應該出現下面B5等倍數值)
頁輸入ViewSource的Fileds
代碼是如何工作的:
- 的代碼創建Internet Explorer中的對象並導航到 site
- 等待,直到頁面完全加載和準備。 (IE。readyState的)
- 創建對象的HTML類
- 提交按鈕
- 迭代直通表dgFunds的每一行輸入值從工作表Sheet(txtDateBegin,txtDateEnd,lstCompany)
- 點擊該輸入字段和轉儲到Excel中Sheet2中
代碼:
Dim IE As Object
Sub Website()
Dim Doc As Object, lastRow As Long, tblTR As Object
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
navigate:
IE.navigate "http://www.spk.gov.tr/apps/MutualFundsPortfolioValues/FundsInfosFP.aspx?ctype=E&submenuheader=0"
Do While IE.readystate <> 4: DoEvents: Loop
Set Doc = CreateObject("htmlfile")
Set Doc = IE.document
If Doc Is Nothing Then GoTo navigate
Set txtDtBegin = Doc.getelementbyid("txtDateBegin")
txtDtBegin.Value = Format(Sheet1.Range("B3").Value, "dd.MM.yyyy")
Set txtDtEnd = Doc.getelementbyid("txtDateEnd")
txtDtEnd.Value = Format(Sheet1.Range("B4").Value, "dd.MM.yyyy")
lastRow = Sheet1.Range("B65000").End(xlUp).row
If lastRow < 5 Then Exit Sub
For i = 5 To lastRow
Set company = Doc.getelementbyid("lstCompany")
For x = 0 To company.Options.Length - 1
If company.Options(x).Text = Sheet1.Range("B" & i) Then
company.selectedIndex = x
Set btnCompanyAdd = Doc.getelementbyid("btnCompanyAdd")
btnCompanyAdd.Click
Set btnCompanyAdd = Nothing
wait
Exit For
End If
Next
Next
wait
Set btnSubmit = Doc.getelementbyid("btnSubmit")
btnSubmit.Click
wait
Set tbldgFunds = Doc.getelementbyid("dgFunds")
Set tblTR = tbldgFunds.getelementsbytagname("tr")
Dim row As Long, col As Long
row = 1
col = 1
On Error Resume Next
For Each r In tblTR
If row = 1 Then
For Each cell In r.getelementsbytagname("th")
Sheet2.Cells(row, col) = cell.innerText
col = col + 1
Next
row = row + 1
col = 1
Else
For Each cell In r.getelementsbytagname("td")
Sheet2.Cells(row, col) = cell.innerText
col = col + 1
Next
row = row + 1
col = 1
End If
Next
IE.Quit
Set IE = Nothing
MsgBox "Done"
End Sub
Sub wait()
Application.wait Now + TimeSerial(0, 0, 10)
Do While IE.readystate <> 4: DoEvents: Loop
End Sub
輸出繼電器表在表2
HTH
你有辦法來自動填充該網頁上列出生成你想要的數據?如果你不能這樣做,那麼你最好使用「下載爲xls」選項,因爲無論如何你都必須手動完成。 – NickSlash 2013-04-11 23:15:37
旁註:可能要使用另一個圖像主機,很多彈出窗口都是NSFW – NickSlash 2013-04-11 23:18:00
我該如何實現自動化?我需要在該頁面上命名爲Allianz的公司的數據...我已將示例excel文件添加到http://uploading.com/folders/get/b491mfb6/excel-web-query – 2013-04-11 23:30:19