如何在VBA Excel 2010中显示等待屏幕 [英] How to show a wait screen in VBA Excel 2010

查看:91
本文介绍了如何在VBA Excel 2010中显示等待屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些工作簿上正在运行的宏,以及一个显示其进度的状态屏幕,因此用户不必盯着空白屏幕或Excel的加载屏幕.大概还是我.状态页起作用,它将在宏运行时更新,但是excel在宏运行完后才会显示任何状态页.如何显示我的状态屏幕?

I have macros that are running on some workbooks and a status screen that shows their progress so the user does not have to stare at a blank screen or the loading screen of Excel. Or so I though. The status page works, it will update as the macros run, but excel will not show any of it until after the macros finish running. How do I show my status screen?

status = "SheetName"

Private Sub Workbook_Open()
    'Make sure that the screen is active
    Sheets(status).Activate
    Sheets(status).Select
End Sub

推荐答案

如果状态屏幕的目的只是在宏运行时提供一些反馈,那么一种快速简便的替代方法是使用状态栏.这是一个示例:

If the purpose of your status screen is simply to give some feedback while your macros are running, a quick and easy alternative is to use the Status Bar. Here's a sample:

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

这篇关于如何在VBA Excel 2010中显示等待屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆