後來在網上找到答案,程式碼如下請參考[attach]27212[/attach]
Sub testname()
stock_name = "hnp"
downprice (stock_name)
End Sub
Function downprice(stock_name)
'下載檔案
Filename = Application.ActiveWorkbook.Name
Dim myURL As String
myURL = "yahoo finance網址, 權限不足請參考程式碼"
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.send
myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile ("D:\" & stock_name & ".csv")
oStream.Close
End If