我为Word和Excel构建VBA应用程序,有没有办法访问有时出现在Office状态栏中的进度条。

有帮助吗?

解决方案

以下将模拟Excel状态栏中的进度条:

Public Sub UpdateStatusBar(percent As Double, Optional Message As String = "")

    Const maxBars As Long = 20
    Const before As String = "["
    Const after As String = "]"

    Dim bar As String
    Dim notBar As String
    Dim numBars As Long

    bar = Chr(31)
    notBar = Chr(151)
    numBars = percent * maxBars

    Application.StatusBar = _
    before & Application.Rept(bar, numBars) & Application.Rept(notBar, maxBars - numBars) & after & " " & _
         Message & " (" & PercentageToString(percent) & "%)"

    DoEvents

End Sub

其他提示

我还建议记录状态栏的当前状态,然后在完成所有操作后将其恢复。

Dim OldStatus
With Application
    OldStatus = .DisplayStatusBar
    .DisplayStatusBar = True
    .StatusBar = "Doing my duty, please wait..."
End With
' Do what you do best here (you can refresh the .StatusBar message with updted, as needed)
With Application
    .StatusBar = False
    .DisplayStatusBar = OldStatus
End With

我没有访问进度条,但我过去曾使用过这样的方法将任务状态文本放在状态栏中...

Sub StatusBarExample()
    Application.ScreenUpdating = False 
    ' turns off screen updating
    Application.DisplayStatusBar = True 
    ' makes sure that the statusbar is visible
    Application.StatusBar = "Please wait while performing task 1..."
    ' add some code for task 1 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = "Please wait while performing task 2..."
    ' add some code for task 2 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = False 
    ' gives control of the statusbar back to the programme
End Sub

AFAIK,无法再现Word&amp ;;使用的蓝线点。 Excel显示100%的进度,例如打开文件时。

我记得曾经看到一些代码在状态栏中复制它,但它很复杂,我不推荐它,当它足够说而不是说“X%完成”时。在状态栏中,使用Application.StatusBar。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top