我想从互联网上下载一个文件(它是一个execl文件),所以我想使用VBA自动完成整个过程。我有文件的地址,但我只想下载然后保存。另一件事是它只能在Internet Explorer中打开,文件无法在chrome或firefox中打开。
答案 0 :(得分:3)
使用URLDownloadToFile
API函数
#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