我有以下代码可以很好地在一个循环中显示每个定义的工作表20秒。我希望能够在每次循环后或以定义的间隔刷新工作簿。在代码中插入ActiveWorkbook.RefreshAll似乎不起作用。
非常感谢任何帮助!
非常感谢提前
Sub Test2()
Dim i As Long, j As Long, t As Single, str As String
Dim MyArray As Variant
MyArray = Array("Sheet1", "Sheet2", "Sheet4", "Sheet6")
For j = LBound(MyArray) To UBound(MyArray)
On Error GoTo exit_
Application.EnableCancelKey = xlErrorHandler
str = MyArray(j)
Sheets(str).Select
t = Timer + 1
Application.Wait Now + TimeSerial(0, 0, 20)
If Timer < t Then Exit Sub
If j = UBound(MyArray) Then
j = -1
Else
j = j
End If
Next j
exit_:
End Sub
答案 0 :(得分:0)
感谢DecimalTurn的帮助,以下代码在禁用后台刷新后仍然有效:
Sub Test2()
Dim i As Long, j As Long, t As Single, str As String
Dim MyArray As Variant
MyArray = Array("Sheet1", "Sheet2", "Sheet4", "Sheet6")
For j = LBound(MyArray) To UBound(MyArray)
On Error GoTo exit_
ActiveWorkbook.RefreshAll
DoEvents
Application.EnableCancelKey = xlErrorHandler
str = MyArray(j)
Sheets(str).Select
t = Timer + 1
Application.Wait Now + TimeSerial(0, 0, 20)
If Timer < t Then Exit Sub
If j = UBound(MyArray) Then
j = -1
Else
j = j
End If
Next j
exit_:
End Sub