gpt4 book ai didi

excel - URLDownloadToFile - 下载文件中数据丢失

转载 作者:行者123 更新时间:2023-12-03 02:58:39 26 4
gpt4 key购买 nike

在 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

最佳答案

我也有类似的问题。我使用以下代码,但收到“溢出”消息:

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

关于excel - URLDownloadToFile - 下载文件中数据丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12269941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com