这个Excel VBA命令宏出了什么问题?

时间:2017-01-08 20:02:21

标签: excel vba

尝试让我的整个工作簿重新计算。

有时它会给我

  

不明确的名称错误RE:Workbook_RefreshAll()

有时其他东西。

我做错了什么? Office 365 - Excel。

Public RunWhen As Double
Public Const cRunIntervalSeconds = 0
Public Const cRunWhat = "Workbook_RefreshAll()"

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, cRunIntervalSeconds, 1)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
         Schedule:=True
End Sub

Sub StopTimer()
   On Error Resume Next
   Application.OnTime EarliestTime:=RunWhen, _
       Procedure:=cRunWhat, Schedule:=False
End Sub

Sub Workbook_RefreshAll()
    Application.CalculateFullRebuild
    ActiveWorkbook.RefreshAll
    Call StartTimer
End Sub

1 个答案:

答案 0 :(得分:0)

请试试这个:

Option Explicit

Public RunWhen As Double
Public Const cRunIntervalSeconds = 0
Public Const cRunWhat as String = "Refresh"

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, cRunIntervalSeconds, 1)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
End Sub

Sub StopTimer()
   On Error Resume Next
   Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=False       
End Sub 

Sub Refresh()    
   Application.CalculateFullRebuild
   ActiveWorkbook.RefreshAll
   StartTimer    
End Sub