VBA 刷新表单
VBA refresh form
我有一个简单的进度条。当我通过循环进行迭代时,我想填充它,但我只看到我的表单具有 0 和 100 进度值,因此它在循环期间不会刷新。如何实现运行时刷新?谢谢!
Sub test()
UserForm1.Show (False)
DoEvents
For i = 1 To 700
For j = 1 To 5000
UserForm1.Label1.Caption = 100 * i / 700 & "% Completed"
UserForm1.Bar.Width = 200 * i / 700 '200 - width of the bar
Next j
Next i
End Sub
你只是把 DoEvents
放在了错误的地方。试试这个。
Sub test()
UserForm1.Show vbModeless
For i = 1 To 700
For j = 1 To 5000
UserForm1.Label1.Caption = 100 * i / 700 & "% Completed"
UserForm1.Bar.Width = 200 * i / 700 '200 - width of the bar
DoEvents
Next
Next
End Sub
我有一个简单的进度条。当我通过循环进行迭代时,我想填充它,但我只看到我的表单具有 0 和 100 进度值,因此它在循环期间不会刷新。如何实现运行时刷新?谢谢!
Sub test()
UserForm1.Show (False)
DoEvents
For i = 1 To 700
For j = 1 To 5000
UserForm1.Label1.Caption = 100 * i / 700 & "% Completed"
UserForm1.Bar.Width = 200 * i / 700 '200 - width of the bar
Next j
Next i
End Sub
你只是把 DoEvents
放在了错误的地方。试试这个。
Sub test()
UserForm1.Show vbModeless
For i = 1 To 700
For j = 1 To 5000
UserForm1.Label1.Caption = 100 * i / 700 & "% Completed"
UserForm1.Bar.Width = 200 * i / 700 '200 - width of the bar
DoEvents
Next
Next
End Sub