我正在尝试将Google Maps API用于大约2,000个地点。我被告知API只允许每十秒进行十次计算,因此我们需要Excel表来执行此操作。我的代码:
'recalculate cells
Sub Recalculatecells()
Dim irow As Integer
Dim i As Integer
Dim j As Integer
' Worksheets("Sheet2").Active
Range("A1").Select
Selection.End(xlDown).Select
iRow = ActiveCell.Row
Range("N1").Value = irow
For i = 1 To iRow
Range("N" & Str(i)).Formula = "=GetCoordinates(A" & i & ")"
j = j + 1
If j = 10 Then
Application.Wait (Now + TimeValue("00:00:10"))
j = 0
Else
j = j + 1
End If
Next i
End Sub
目前这条线上有错误:
Range("N" & Str(i)).Formula= "=GetCoordinates(A" & i & ")"
(注意:=getcoordinates
是运行Maps API的功能。)
我不知道为什么会出现错误,一旦删除此错误,代码是否有效?
答案 0 :(得分:1)
Application.OnTime method可以调用它所在的例程。
Sub Recalculatecells()
Application.StatusBar = "Calculating ..."
Worksheets("Sheet2").Range("N1:N10").Calculate
Application.StatusBar = vbNullString
'put something here to optionally exit the timed loop
Application.OnTime Now + TimeSerial(0, 0, 10), "Recalculatecells"
End Sub
我发现这样可以更自由地处理工作簿,而不是保持在同一个子程序中并且使用For ... Next
增量计数器。