How to do a Dowload in IE via VBA?

1

Hello, I'm using the following code to start a dowload in Intenet Explorer.

Public Sub Dashboard()
    Dim Navegador As InternetExplorer
    Dim objShellWindows As New SHDocVw.ShellWindows
    Dim currentWindow As HTMLWindowProxy
    Dim url As String
    
    On Error GoTo Erro
    url = "http://..................../"
    Set Navegador = New InternetExplorer
    Navegador.navigate url
    Navegador.Visible = True

    Do While Navegador.readyState <> 4
        DoEvents
    Loop
    
    'Faz login
    Navegador.document.getElementById("usuario").Value = "xxxxxxxx"
    Navegador.document.getElementById("senha").Value = "xxxxxx"
    Navegador.document.getElementById("bt_entrar").Click
'    Set Navegador = Nothing
'    Set Navegador = New InternetExplorer
'    Navegador.navigate url
'    Navegador.Visible = True
    
    Do While Navegador.readyState <> 4
        DoEvents
    Loop
    
    Navegador.document.getElementById("submenu2_SatisfacaoGeral").Click
    Set currentWindow = Navegador.document.parentWindow
    currentWindow.execScript code:="chart.exportChart()"

Erro:
    MsgBox Err.Description
    Resume Next
 End Sub

It happens that I do not know how I can "save as download" by setting the folder and filename.

    
asked by anonymous 06.10.2017 / 19:40

1 answer

0

You can interact with the PDF, for example by downloading it by the URL created for a specified folder, using the URLDownloadToFile function,

Declare Function URLDownloadToFile _
    Lib "urlmon" Alias "URLDownloadToFileA" _
    (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Function DownloadFile(URL As String, LocalFilename As String) As Boolean
        Dim lngRetVal As Long
        lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
        If lngRetVal = 0 Then DownloadFile = True
    End Function
    Sub test()
        URL = Navegador.LocationURL 'URL do pdf
        DownloadFile URL, "C:\PASTA\EXEMPLO.pdf" 'Pasta e nome do arquivo
    End Sub
    
29.10.2017 / 19:34