我正在通过Excel中的按钮在VBA中执行以下代码。但是,无论我在两次按钮单击之间等待了多长时间,网站数据都在更新,并且excel似乎没有更新。只有当我关闭excel并重新打开时,数据才会更新。如何获得我的代码以每次点击获取实时数据?
Public Sub exceljson()
Dim http As Object
Dim JSON As Object
Dim inst As String
Dim arrInst() As String
Dim arrRatio() As Double
Dim arrBid() As Double
Dim arrAsk() As Double
Dim arrMin() As Double
Dim arrMaxk() As Double
Dim size As Integer
Dim i As Integer, x As Integer
Set http = CreateObject("MSXML2.XMLHTTP")
'Counts the number of cells that are not empty and the values within the list of arguments.
Set myRange = Range("A2:A100")
size = WorksheetFunction.CountA(myRange)
'Sets the array of instruments to the size determined above
'Loops through each row and inputs that instrument name into the array
ReDim arrInst(size)
For i = 1 To size
arrInst(i) = UCase(Range("E1").Offset(i).Value)
Next i
'Get data needed from API for each leg and print in sheet
For i = 1 To UBound(arrInst)
http.Open "GET", ("https://testapp.deribit.com/api/v2/public/ticker?instrument_name=" & arrInst(i)), False
http.Send
Set JSON = ParseJson(http.ResponseText)
Cells(i, 7).Offset(1).Value = JSON("result")("min_price")
Cells(i, 8).Offset(1).Value = JSON("result")("best_bid_price")
Cells(i, 9).Offset(1).Value = JSON("result")("mark_price")
Cells(i, 10).Offset(1).Value = JSON("result")("best_ask_price")
Cells(i, 11).Offset(1).Value = JSON("result")("max_price")
Next i
End Sub
答案 0 :(得分:0)
我添加了以下代码:
http.SetRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"