5

Word と Excel の両方で VBA アプリケーションを作成しています。Office のステータス バーに時々表示される進行状況バーにアクセスする方法はありますか。

4

4 に答える 4

4

以下は、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
于 2008-11-20T17:38:15.877 に答える
3

さらに、StatusBarの現在の状態を記録し、すべてが完了したら復元することをお勧めします。

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
于 2008-10-22T19:35:11.600 に答える
0

プログレスバーにアクセスしたことはありませんが、過去にこのようなものを使用してタスクステータステキストをステータスバーに配置しました...

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
于 2008-10-20T09:10:44.093 に答える
0

私の知る限り、ファイルを開くときなど、Word と Excel で 100% に向けた進行状況を示すために使用される青いドットの線を再現する方法はありません。

ステータス バーでそれを再現するコードを見たことがあるのを覚えていますが、それは複雑で、Application.StatusBar を使用してステータス バーに "X% 完了" と表示するだけで十分な場合は、お勧めしません。

于 2008-10-26T11:49:44.323 に答える