VBA中用户窗体上的实时更新(动态)标签

VBA中用户窗体上的实时更新(动态)标签,vba,status,Vba,Status,我正在尝试使用VBA创建(和更新)一个状态窗口。显示状态窗口时,“在后台”正在复制/编辑行 状态窗口(带有动态元素的静态用户表单)由以下两个过程处理(我通过删除一些格式元素(如title等)简化了它们)和调用它们的“主过程”: 'Create and initialize window Sub ShowStatusWindow(strText As String) 'Userform UserForm1.Height = 50 UserForm1.Width = 200

我正在尝试使用VBA创建(和更新)一个状态窗口。显示状态窗口时,“在后台”正在复制/编辑行

状态窗口(带有动态元素的静态用户表单)由以下两个过程处理(我通过删除一些格式元素(如title等)简化了它们)和调用它们的“主过程”:

'Create and initialize window
Sub ShowStatusWindow(strText As String)

    'Userform
    UserForm1.Height = 50
    UserForm1.Width = 200

    'Label
    Dim messageLabel As MSForms.Label
    Set messageLabel = UserForm1.Controls.Add("Forms.Label.1", "messageLabel_1")
    messageLabel.Top = 10
    messageLabel.Left = 10
    messageLabel.Width = 200
    messageLabel.Caption = strText 

    'Show Status-Window
    UserForm1.Show vbModeless
    DoEvents

    End Sub

'Changing text in status window
Sub ChangeStatusWindow(strText As String)

    UserForm1.Controls("tmpMessageLabel_1").Caption = strText

    'Repaint and DoEvents does not seem to help here
    UserForm1.Repaint
    DoEvents

    End Sub

Sub main()

    ShowStatusWindow("Start")
    For index = 1 To indexMax

        'Change text in Status window to e.g. "iteration:1/2")
        ChangeStatusWindow("iteration:" & index "/" & indexMax)

        'Repaint and DoEvents does not seem to help here either
        UserForm1.Repaint
        DoEvents

        'Do Stuff
        Next index

    End Sub
第一次使用
ChangeStatusWindow()
时,它运行良好(在逐步调试期间),但现在用户表单中的标签不会更新。我不知道我搞砸了什么。。。如有任何提示,将不胜感激

注意:作为一种(不需要的)解决方法,我关闭、更新并打开状态窗口UserForm,以确定哪种方式工作,但闪烁效果需要人为地“减慢”循环