我有一些在某些工作簿上运行的宏和一个显示其进度的状态屏幕,因此用户无需盯着空白屏幕或Excel的加载屏幕。或者我也是。状态页面工作,它将在宏运行时更新,但excel在宏完成运行之前不会显示任何内容。如何显示状态屏幕?
status = "SheetName"
Private Sub Workbook_Open()
'Make sure that the screen is active
Sheets(status).Activate
Sheets(status).Select
End Sub
答案 0 :(得分:2)
如果您的状态屏幕的目的只是在宏运行时给出一些反馈,那么快速简便的替代方法就是使用状态栏。这是一个示例:
Sub YourMacro()
Dim StatusOld As Boolean, CalcOld As XlCalculation
' Capture Initial Settings
StatusOld = Application.DisplayStatusBar
' Doing these will speed up your code
CalcOld = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error GoTo EH
' Your code...
' Every so often while your code is running
Application.StatusBar = "Something Useful..."
' After all your code is done
CleanUp:
' Put things back like they were
Application.StatusBar = False
Application.Calculation = CalcOld
Application.DisplayStatusBar = StatusOld
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
EH:
' Your error handler...
GoTo CleanUp
End Sub
答案 1 :(得分:0)
每次更新(VBA指令)后都必须调用DoEvents。这将使处理器的时间瞬间恢复到Excel,并且它将用它来重绘屏幕。你必须要小心这一点,因为它还允许你的用户点击电子表格并搞砸了。