简体   繁体   English

Excel VBA进度栏

[英]Excel VBA Progress Bar

I want to pop up a progress bar when my macro enters in a big loop, so that the user is aware that everything is fine, and the the program is just taking some time to complete a task. 当我的宏进入一个大循环时,我想弹出一个进度条,以便用户意识到一切都很好,并且程序仅花费一些时间来完成任务。

I found this tutorial, followed step by step and everything looks fine (I managed to implement the progress bar of the example without any issue). 我找到了教程,然后逐步进行,一切看起来都很好(我设法实现了示例的进度条,没有任何问题)。

But now, of course, I want to change the code of the progress bar to my code. 但是现在,当然,我想将进度条的代码更改为我的代码。 When I do that the problem is that: 当我这样做时,问题是:

a) The progress bar is not disappearing after UserForm1.Hide (which is not at the tutorial above, I just figured that this is what I have to call to dismiss the progress bar, but it is not working); a)在UserForm1.Hide之后进度条不会消失(这不在上面的教程中,我只是想这是我必须调用以关闭进度条,但它不起作用);

b) When I manually close the progress bar once it is 100%, the macro takes about 10 seconds to continue to run the code. b)当进度条是100%时,我手动将其关闭时,该宏大约需要10秒钟才能继续运行代码。

Any suggestions? 有什么建议么?

Thank you, 谢谢,

Sub myCode()

    '... long code here

    Dim pctCompl As Single
    UserForm1.Show

    Dim base As Double
    For base = 2 To numberOfLines
        '...some code here too
        pctCompl = (numberOfLines - 2) / numberOfLines
        progress pctCompl
    Next base

    ' Not working.
    UserForm1.Hide

    'Taking too long to open after the progress bar is closed.
    Workbooks.Open Filename:="myPath...", UpdateLinks:=0, ReadOnly:=True

    'Some code here too...

End Sub


Sub progress(pctCompl As Single)

    UserForm1.Text.Caption = pctCompl & "% Completed"
    UserForm1.Bar.Width = pctCompl * 2

    DoEvents

End Sub

This is a sample: how progressbar works 这是一个示例: 进度条如何工作

Take look on this. 看看这个。 Try to rewrite your cody using my code lines. 尝试使用我的代码行重写您的科迪。

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

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