[英]How to complete the file download and “save as” in Internet Explorer by VBA
我正在嘗試替換每天下載的文檔。 但是我點擊下載按鈕后不知道自己需要做什么。 我需要在文檔中保存具有特定名稱的文檔
按照代碼:
Dim IE As Object
Dim n, Period1, Period2 As Double
'retorna o internet explorer-return the correct period
Period1 = "201612"
Period2 = "201612"
'abre o internet explorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www2.susep.gov.br/menuestatistica/SES/principal.aspx"
IE.Visible = True
Application.Wait (Now + TimeValue("00:00:02"))
'seleciona as operações desejadas
IE.document.getElementById("ctl00_ContentPlaceHolder1_edSelProd").SelectedIndex = "8"
IE.document.getElementById("ctl00_ContentPlaceHolder1_btnConsultar").Click
'seleciona o periodo
Application.Wait (Now + TimeValue("00:00:02"))
Set ieDoc = IE.document
ieDoc.getElementById("ctl00_ContentPlaceHolder1_edInicioPer").Value = Period1
ieDoc.getElementById("ctl00_ContentPlaceHolder1_edFimPer").Value = Period2
'seleciona as empresas
IE.document.getElementById("ctl00_ContentPlaceHolder1_edEmpresas").SelectedIndex = "0"
ieDoc.getElementById("ctl00_ContentPlaceHolder1_Button1").Click
Application.Wait (Now + TimeValue("00:00:02"))
ieDoc.getElementById("ctl00_ContentPlaceHolder1_Button1").Click
我嘗試使用命令找到直接保存文件的其他解決方案,但似乎你需要使用不推薦的注冊表項。 所以我以下面的方式做到了
IE.document.getElementById("downXls").Click Application.Wait (Now + TimeValue("0:00:7")) CreateObject("WScript.Shell").SendKeys "%s" Application.Wait Now + TimeValue("00:00:02") IE.Quit Application.DisplayAlerts = False FSO.MoveFile Source:=sfolder & "ValueResearch-Stocks-" & vert & "-" & dateval & ".xls", Destination:=DestinFileName FSO.MoveFile Source:=sfolder & "ValueResearch-Stocks-" & vert & "-" & dateval & ".xlsx", Destination:=DestinFileName
所以在這里你需要在變量中定義路徑,然后你只需要將下載的文件移動到所需的位置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.