如何通过VBA下载和保存文档

我正在尝试replace每天下载文档。 但是我不知道我点击下载button后需要做什么。 我需要在文档中保存具有特定名称的文档

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 

我设法做到以下几点:

 Option Explicit Sub TestMe() Dim IE As Object Dim n As Double, Period1 As Double, Period2 As Double Dim ieDoc As Object '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:03")) ieDoc.getElementById("ctl00_ContentPlaceHolder1_Button1").Click AppActivate IE.name, 1 SendKeys "%{s}" SendKeys "{ENTER}" End Sub 

用巴西(葡萄牙语)的sendkeys播放一下,它们应该与“s”不同。 阅读更多信息: https : //msdn.microsoft.com/en-us/library/office/ff821075.aspx

我的想法是导航到另存为button(在葡萄牙语,其他东西),并使用SendKeys来获得它。 在这里输入图像说明

像这样的东西应该是可能的:

 AppActivate IE.Name, 2 SendKeys "{TAB}{TAB}" SendKeys "{DOWN}" SendKeys "%{a}" SendKeys "{ENTER}"