【发布时间】:2017-09-04 22:44:02
【问题描述】:
首先我不是程序员,我是金融专业的学生,所以我制作了一个带有宏的 Excel 文件,https://www.nseindia.com/products/content/equities/equities/eq_security.htm 的所有字段都会自动填充。但是我无法单击如何单击“以 csv 格式下载文件”。点击链接的 VBA 代码是什么?
Private Sub CommandButton1_Click()
Dim IE As New InternetExplorer
Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Sheet1")
Dim oEleCol As MSHTML.IHTMLElementCollection
Dim oEle As MSHTML.IHTMLElement
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
oEleCol.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
注意 - 输入参数将是 符号 - SBIN 系列 - 情商 时间段 - 2016 年 1 月 1 日 时间段至 - 2016 年 1 月 12 日
【问题讨论】:
-
请添加您的代码以便改进。
-
应该
oEleCol.Click是oEle.Click吗? -
oEle.Click,但这部分代码不起作用。
-
“在 csv 文件中下载文件”的 HTML 代码如下所示 下载csv格式文件
标签: javascript vba excel