作者yutang918 (高级牛奶糖)
看板Visual_Basic
标题[VBA ] 网路下载csv档请教
时间Wed Jan 23 18:08:14 2019
大家好
小弟想从网页上的下载连结
下载csv档
再将资料贴到excel上
以下是VBA程式码:
Sub get_csv()
Workbooks("stock.xlsm").Worksheets("data").Activate
Dim myURL As String
myURL = "
https://query1.finance.yahoo.com/v7/finance/download/CGN.SI?period1=1388505600&period2=1515081600&interval=1d&events=history&crumb=wdEbtptikGY"
Dim HttpReq As Object
Set HttpReq = CreateObject("MSXML2.XMLHTTP.3.0")
HttpReq.Open "GET", myURL, False
HttpReq.send
Range("a1") = HttpReq.responseText
End Sub
但在执行後
A1储存格会出现以下讯息:
{
"finance": {
"error": {
"code": "Unauthorized",
"description": "Invalid cookie"
}
}
}
手动去浏览器输入以上网址可以成功下载资料
但用巨集执就会失败QQ
想请问这个情形有办法解决吗?
感谢各位高手!!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 137.132.183.1
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1548238097.A.3E5.html
※ 编辑: yutang918 (137.132.183.1), 01/23/2019 18:09:42