我正在尝试下载在IE Web浏览器中打开的.pdf文件。这是我的代码:
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
Sub DownPDF()
Dim sUrl As String
Dim sPath As String
sPath = "C:\Users\adhil\Documents"
sUrl = "http://analytics.ncsu.edu/sesug/2010/HOW01.Waller.pdf"
Ret = URLDownloadToFile(0, sUrl, sPath, 0, 0)
If Ret = 0 Then
Debug.Print sUrl & " downloaded to " & sPath
Else
Debug.Print sUrl & " not downloaded"
End If
End Sub
但是,虽然响应是这样说的,但我无法下载文件。
任何人都可以帮助我吗?
答案 0 :(得分:1)
该函数要求参数szFileName
是文件的完整路径名,而不是文件夹。
试试这个:
sPath = "C:\Users\adhil\Documents\HOW01.Waller.pdf"
我和我一起工作,但是当省略目标文件名时它没有用。