我所有的人都不是程序员,我是一名财务专业的学生,因此我使用宏创建一个Excel文件,其中https://www.nseindia.com/products/content/equities/equities/eq_security.htm的所有字段将自动填充。但是,我无法点击如何点击"以csv格式下载文件"。单击链接的VBA代码是什么?
sed
注 - 输入参数为 符号 - SBIN 系列 - EQ 时间段 - 2016年1月1日 时间段 - 2016年1月12日
答案 0 :(得分:1)
我将IE更改为object并将oEleCol.Click
修改为oEle.Click
并且它有效。但是它要求确认保存,因此您必须启用自动确认或查找如何实施Send Keys
Private Sub CommandButton1_Click()
Dim IE As Object
Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Plan1")
'Dim oEleCol As MSHTML.IHTMLElementCollection
'Dim oEle As MSHTML.IHTMLElement
Set IE = CreateObject("InternetExplorer.Application")
With IE
'Set IE = CreateObject("InternetExplorer.Application")
' Set IE
.Visible = True
'ShowWindow .hwnd, SW_SHOWMAXIMIZED
' Navigate to URL
.Navigate "https://www.nseindia.com/products/content/equities/equities/eq_security.htm"
' Wait for page to be ready
While .Busy
DoEvents 'wait until IE is done loading page.
Wend
' Set criteria
.document.all("symbol").Value = oW.Range("B1")
.document.all("series").Value = oW.Range("B2")
.document.getElementById("rdDateToDate").Click
' Wait for page to be ready
While .Busy
DoEvents 'wait until IE is done loading page.
Wend
' Set remaining criteria
.document.all("fromDate").Value = oW.Range("B3")
.document.all("toDate").Value = oW.Range("D3")
' Submit criteria
.document.getElementById("submitMe").Click
' Wait for page to be ready
While .Busy
DoEvents 'wait until IE is done loading page.
Wend
' Find the link to download file
Set oEleCol = .document.getElementsByTagName("A")
For Each oEle In oEleCol
If oEle.innerhtml = "Download file in csv format" Then
oEle.Click
Exit For
End If
Next
' Wait for page to be ready
While .Busy
DoEvents 'wait until IE is done loading page.
Wend
End With
End Sub
这种方式对我有用。