本文介绍了URLDownloadToFile-下载的文件中缺少数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VBA中使用URLDownloadToFile
,我正在尝试下载文件.问题是正在下载空白文件.知道为什么数据丢失了吗?
Using URLDownloadToFile
in VBA, I am trying to download a file. The problem is that a blank file is getting downloaded. Any idea why the data is missing?
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
推荐答案
我有一个类似的问题.我使用以下代码,但收到溢出"消息:
I have a similar issue. I use the following code but got an "overflow" message:
Sub downloadFile()
Dim targetFile As String, targetUrl As String, returnVal As Integer
target = "http://www.ishares.com/us/products/239454/ishares-20-year-treasury-bond-etf/1395165510757.ajax?fileType=xls&fileName=iShares-20-Year-Treasury-Bond-ETF"
strSavePath = "C:\testdownload.txt"
returnVal = URLDownloadToFile(0, target, strSavePath, 0, 0)
If returnVal = 0 Then
Debug.Print "Download ok!"
Else
Debug.Print "Error"
End If
End Sub
这篇关于URLDownloadToFile-下载的文件中缺少数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!