简体   繁体   中英

download download.csv file from internet explorer

Team,

URL=https://www.nseindia.com/option-chain

i want to download download.csv file from internet explorer but manually save requiring to do in below given code, can someone improvise the same.

Code-

Sub Get_Option_Chain_Data_IE()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLELements As MSHTML.IHTMLElementCollection
Dim HTMLElement As MSHTML.IHTMLElement

'IE.Visible = True
IE.navigate "https://www.nseindia.com/option-chain"

Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.document

Set HTMLElement = HTMLDoc.getElementById("downloadOCTable")

    HTMLElement.Click

End Sub

We can press Alt+S to save the download files in IE. So in VBA, we can use Application.SendKeys "%{s}" to simulate the keystroke to click the Save button. You can also refer to SendKeys statement .

The sample code snippet is like below. I test it and it works well:

Set HTMLElement = HTMLDoc.getElementById("downloadOCTable")
HTMLElement.Click

Application.Wait (Now + TimeValue("00:00:03"))
Application.SendKeys "%{s}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM