如何通过VBA来完成文件下载和“另存为” Internet Explorer中

问题描述 投票:1回答:1

我试图替换文件,我下载做日常。但我不知道我需要什么我点击下载按钮后做。我需要将文件保存在我的文档的具体名称

遵循代码:

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
excel vba excel-vba
1个回答
0
投票

我试图寻找的使用命令直接将文件保存其他的解决方案,但似乎你需要玩的不推荐使用的注册表项。所以,我做了一个下面的方式

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
    

所以在这里你需要定义变量的路径,然后你只需要下载的文件移动到所需的位置

© www.soinside.com 2019 - 2024. All rights reserved.