简体   繁体   English

如何将宏添加到进度栏

[英]How to add macro to progress bar

I have this Macro that makes a progress bar in the status bar, but I can not get how to add a macro to it. 我有一个在状态栏中显示进度条的宏,但无法获取向其添加宏的方法。

ie if I have a sub, say, Sub LongExacutionTime() how do I apply ShowProgress to it 也就是说,如果我有一个子,例如Sub LongExacutionTime(),我如何将ShowProgress应用于它

I tried changing 'Application.Wait Now + TimeValue("00:00:01") '<– Replace this line with your own code to do something to this 我尝试更改'Application.Wait Now + TimeValue("00:00:01") '<– Replace this line with your own code to do something以对此执行操作

Call LongExacutionTimeLongExacutionTime but it executes LongExacutionTimeLongExacutionTime 10 times (once for each iteration of the loop) Call LongExacutionTimeLongExacutionTime但它会执行LongExacutionTimeLongExacutionTime 10次​​(每次循环迭代一次)

This seems like it should be simple to get and maybe it is but I am not getting it 这似乎应该很容易获得,也许是,但是我没有得到

any insight into this is appriciated 任何对此的见识都适用

Thanks 谢谢

Sub ShowProgress()
Dim strBar As String
Dim lngLoop As Long


'make StatusBar visible
Application.DisplayStatusBar = True
strBar = String(0, ChrW(&H25A0)) & String(10, ChrW(&H25A1))
Application.StatusBar = strBar & "Starting…"
Application.Wait Now + TimeValue("00:0:01")

 For lngLoop = 1 To 1
     strBar = String(lngLoop, ChrW(&H25A0)) & String(10 - lngLoop, ChrW(&H25A1))
     Application.StatusBar = strBar & " Processing…"
    'Application.Wait Now + TimeValue("00:00:01") '<– Replace this line with your own   code to do something        
   Next

'Relinquish the StatusBar
Application.StatusBar = False
End Sub

I think you're looking for something like this: 我认为您正在寻找这样的东西:

Sub ShowProgress(strMessage As String)

    'make StatusBar visible
    Application.DisplayStatusBar = True
    Application.StatusBar = strMessage

End Sub

Public Sub LongExecutionTime()

    'About to start
    Call ShowProgress("Starting...")

    'Run some other code.  I've put a wait of 5 seconds in so you can see the status bar saying "Starting..."
    Application.Wait Now + TimeValue("00:00:05")
    'Process some stuff
    Call ShowProgress("Processing...")

    'Run some other code.  I've put a wait of 5 seconds in so you can see the status bar saying "Processing..."
    Application.Wait Now + TimeValue("00:00:05")

    Call ShowProgress("FinishingUp..")
    'Same wait
    Application.Wait Now + TimeValue("00:00:05")

    'Turn off StatusBar
    Application.DisplayStatusBar = False

End Sub

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

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