立即盒(debugging窗口)单独显示

如果这是一个愚蠢的问题,我真的很抱歉。 我想要显示一个类似于Immediate窗口的消息框,它将坐在“始终在最前面”,并在不中断VBA程序的情况下滚动倒计时。

我基本上是为40,000行计算数字,每次运行大约需要15分钟。 我不知道它是否仍在运行,或者当前的VBA代码将会完成。

有没有人有build议?

使用状态栏:

 Application.StatusBar = "Row " & rowNum & " of " & rowCount 

最后,清除状态栏:

 Application.StatusBar = False 

你可以通过显示无模式的用户表单来完成 。 下面是一个如何做到这一点的例子。

为了使这个例子正常工作, 你需要添加新的,空的UserForm到你的项目中,并将其改名为frmProgress

 Sub test() Dim form As frmProgress Dim lblProgress As Object Dim i As Long '------------------------------------------------- 'Create an instance of user form and show it modeless on the screen. Set form = New frmProgress With form .Width = 200 .Height = 60 .Caption = "Progress" 'Add label for displaying text... Set lblProgress = .Controls.Add("Forms.Label.1", "lblProgress") '... and format it to meet your requirements. With lblProgress .Width = 200 .Height = 60 .TextAlign = fmTextAlignCenter .Font.Size = 12 .Top = 6 End With Call .Show(vbModeless) End With For i = 1 To 100000 '(Some code ...) DoEvents 'Here the new text is inserted on the message box. lblProgress.Caption = i Next i Call form.Hide End Sub