如果这是一个愚蠢的问题,我真的很抱歉。我想显示一个类似于Immediate
窗口的消息框,它将“始终位于顶部”并滚动倒计时,同时不会中断VBA程序。
我基本上处理40,000行的数字,每次运行大约需要15分钟。我不知道它是否仍在运行或当前的VBA代码何时完成。
有人有建议吗?
答案 0 :(得分:4)
使用状态栏:
Application.StatusBar = "Row " & rowNum & " of " & rowCount
最后,要清除状态栏:
Application.StatusBar = False
答案 1 :(得分:1)
您可以通过显示无模式用户表单来实现。以下是如何执行此操作的示例。
为了使此示例正常工作,您需要向项目中添加新的空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