问题描述
执行子程序时我有时间问题。 例如下面的代码。如果我从VBA编辑器执行它,则需要4秒钟,但是如果我从功能区中的自定义按钮使用以下命令调用它:Public Sub test_sub(控件为IRibbonControl),则需要66秒。我不明白为什么。
'SUB executed from VBA editor:
Public Sub test_sub()
Dim i As Integer
Dim t As Double
t = Timer
For i = 0 To 20
Call generar_resumen
Next i
Debug.Print " tiempo sub = " & Timer - t
End Sub
'SUB executed from button in Excel Ribbon:
Public Sub test_sub(control as IRibbonControl)
Dim i As Integer
Dim t As Double
t = Timer
For i = 0 To 20
Call generar_resumen
Next i
Debug.Print " tiempo sub = " & Timer - t
End Sub
请,有人可以帮助我吗?我不知道该怎么办。
谢谢
解决方法
也许您可以尝试在开始时使用它:
On Error GoTo Err_Exit:
Application.EnableEvents = false
Application.ScreenUpdating = false
最后,您可以再次使用它启用它
Err_Exit:
Application.EnableEvents = true
Application.ScreenUpdating = true