2
在VBA中使用URLDownloadToFile,我試圖下載一個文件。問題是一個空白文件正在下載。任何想法爲什麼數據缺失?VBA - URLDownloadToFile - 在下載的文件中丟失數據
Option Explicit
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
Dim Ret As Long
Sub Sample()
Dim strURL As String
Dim strPath As String
strURL = "https://abc.abcabc.com/cmif-ku/reports/2012/byOwningEntity/Excel/myfilename.xls"
strPath = "C:\Temp\myfilename.xls"
Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)
If Ret = 0 Then
MsgBox "File successfully downloaded"
Else
MsgBox "Unable to download the file"
End If
End Sub
兩件事'1)'分享您正在使用的'strURL'。 '2)'你在'strPath'中缺少一個「\」 –
「空白文件」是指一個實際的空的Excel文件或根本沒有文件? –
返回的內容可能不是Excel文件,而是重定向或其他類型的內容? –