如何在Excel中创建状态对话框

Jon*_*old 3 excel vba excel-vba

我在Excel中创建了一个数据库报告生成器.我正在尝试创建一个对话框,在程序运行时显示状态信息.

当我生成报告时,虽然出现了对话框,但我无法刷新/更新它显示的信息.大多数情况下,对话框仅部分显示.我试过使用.repaint方法,但我仍然得到相同的结果.生成报告后,我只看到完整的对话框.

Gal*_*ian 6

我使用 Excel 自己的状态栏(在窗口的左下角)来显示我过去开发的类似应用程序的进度信息。

如果您只想显示进度中的文本更新,并且根本不需要更新对话框,它会非常有效。

好的@JonnyGold,这是我使用的那种东西的一个例子......

Sub StatusBarExample()
    Application.ScreenUpdating = False 
    ' turns off screen updating
    Application.DisplayStatusBar = True 
    ' makes sure that the statusbar is visible
    Application.StatusBar = "Please wait while performing task 1..."
    ' add some code for task 1 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = "Please wait while performing task 2..."
    ' add some code for task 2 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = False 
    ' gives control of the statusbar back to the programme
End Sub
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!


Mar*_*iek 6

尝试在循环中添加DoEvents调用.这应该允许表单重新绘制并接受其他请求.