gpt4 book ai didi

excel - 使用 excel vba 从 Web 下载 zip 文件

转载 作者:行者123 更新时间:2023-12-03 17:00:48 26 4
gpt4 key购买 nike

我是 excel 新手,我正在关注 this link使用 excel vba 下载 zip 文件。

        UrlFile = "https://www1.nseindia.com/content/historical/EQUITIES/2020/MAR/cm13MAR2020bhav.csv.zip"
On Error GoTo exit_
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", UrlFile, False
.setRequestHeader "Upgrade-Insecure-Requests", "1"
.setRequestHeader "Sec-Fetch-Dest", "document"
.send
If .Status <> 200 Then Exit Function
b() = .responseBody
FN = FreeFile
Open PathName For Binary Access Write As #FN
Put #FN, , b()
exit_:
MsgBox Err.Description
If FN Then Close #FN
Url2File = .Status = 200
End With

在执行 .发送在上面的代码中,它总是导致错误 "指定资源下载失败" .请帮我解决这个问题。

最佳答案

Public Function DownloadFile()

Dim myURL As String
myURL = "https://www1.nseindia.com/content/historical/EQUITIES/2020/MAR/cm13MAR2020bhav.csv.zip"

Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.send

If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile "C:\Users\praburaj\Downloads\file.zip", 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If

End Function

关于excel - 使用 excel vba 从 Web 下载 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61078104/

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