Fisrt всего я не программист, я студент по финансам, поэтому я делаю файл 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 - эквалайзер Период времени с - 1/1/2016 Время до - 1/12/2016
Я изменил IE на объект и зафиксировал 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
Таким образом, это работает для меня.
Application.Wait(Now + TimeValue("00:00:01"))
перед 'Find the link to download file'
oEleCol.Click
бытьoEle.Click
?