简体   繁体   English

如何显示进度条?

[英]How to display a progress bar?

There is much advice on the Internet about how to make a progress bar.网上有很多关于如何制作进度条的建议。

I made a userform, with label and frame and added code to the button:我制作了一个带有标签和框架的用户表单,并向按钮添加了代码:

Private Sub CommandButton1_Click()

For i = 1 To 192
    Cells(i, 1) = "a"
    Label1.Width = i
Next i

End Sub

The progress bar is refreshed only after the end of execution of loop.进度条只有在循环执行结束后才会刷新。

How to refresh a userform?如何刷新用户表单?

DoEvents passes control to the operating system. DoEvents将控制权交给操作系统。 Control is returned after the operating system has finished processing the events in its queue (like screen updates).在操作系统处理完其队列中的事件(如屏幕更新)后,控制权将返回。 This is what you need if you are using a progress bar.如果您使用进度条,这就是您所需要的。

So put a DoEvents inside of your loop.所以在你的循环中放一个DoEvents It will slow it down, but the progress bar should work then.它会减慢它的速度,但进度条应该会起作用。

Private Sub CommandButton1_Click()
  For i = 1 To 192
    Cells(i, 1) = "a"
    Label1.Width = i
    DoEvents
  Next i
End Sub

VBA DoEvents Documentation from Microsoft Microsoft 的 VBA DoEvents 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM