File Download - Excel - Firefox

Asked

Viewed 458 times

0

I have the download link to an XLS file. Every day I need to DOWNLOAD this file (I can only access by firefox), SAVE in a folder to feed my spreadsheet. ( the sheet is "linked" in this file. I need a macro to do: download this file (the link is ready) automatically to a folder.

1 answer

0

Try using the following function adapted with your data:

Sub downloadFile()
    Dim myURL As String

    myURL = "http://portal.convenios.gov.br/images/docs/CGSIS/csv/siconv.zip" ' Coloque sua URL aqui!!!


    Dim WinHttpReq As Object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    WinHttpReq.Open "GET", myURL, False
    WinHttpReq.Send

    myURL = WinHttpReq.ResponseBody
    If WinHttpReq.Status = 200 Then
        Set oStream = CreateObject("ADODB.Stream")
        oStream.Open
        oStream.Type = 1
        oStream.Write WinHttpReq.ResponseBody
        oStream.SaveToFile ("C:\Users\user\Downloads\file.zip")
        oStream.Close
    End If
End Sub

Code adapted from:

https://social.msdn.microsoft.com/Forums/en-US/bd0ee306-7bb5-4ce4-8341-edd9475f84ad/excel-2007-use-vba-to-download-save-csv-from-url

Browser other questions tagged

You are not signed in. Login or sign up in order to post.