Reputation: 43
I wanted to download a file from the internet (its a execl file) so I want to use VBA to automate the entire process. I have the address of the file but I just want to download it and then save it. The other thing is that it can only be opened in internet explorer the file cannot be opened in chrome or firefox.
Upvotes: 0
Views: 1024
Reputation: 2859
Use the URLDownloadToFile
API function
#If VBA7 Then
Private Declare PtrSafe 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
#Else
Private 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
#End If
Sub Demo()
URLDownloadToFile 0, _
"http://www.example.com/myworkbook.xlsx", _
"C:\users\me\documents\myworkbook.xlsx", 0, 0
End Sub
Upvotes: 3