gpt4 book ai didi

javascript - 从 VBA 调用 JavaScript

转载 作者:行者123 更新时间:2023-11-30 21:11:59 26 4
gpt4 key购买 nike

首先,我不是程序员,我是一名金融专业的学生,​​所以我制作了一个带有宏的 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系列-EQ时间段从 - 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

这种方式适合我。

Reference image

关于javascript - 从 VBA 调用 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46038953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com