如何将宏添加到进度条

时间:2014-06-27 17:25:12

标签: excel-vba statusbar vba excel

我有这个宏在状态栏中创建了一个进度条,但我无法获得如何添加宏。

即如果我有一个sub,比如Sub LongExacutionTime(),我如何将ShowProgress应用于它

我尝试将'Application.Wait Now + TimeValue("00:00:01") '<– Replace this line with your own code to do something更改为此

Call LongExacutionTimeLongExacutionTime但它执行LongExacutionTimeLongExacutionTime 10次(每次迭代循环一次)

这似乎应该很容易获得,也许它是,但我没有得到它

对此的任何见解都是适当的

由于

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

1 个答案:

答案 0 :(得分:2)

我认为你正在寻找类似的东西:

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