質問

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

他のヒント

さらに、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

進行状況バーにはアクセスしていませんが、過去にこのようなものを使用して、ステータスバーにタスクステータステキストを配置しました...

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

わかりました、Word&で使用される青い点線を再現する方法はありません。ファイルを開くときなど、100%に向かって進行状況を表示するExcel。

ステータスバーに複製するためのコードを見たことがありますが、複雑だったため、「X%complete」と言うだけで十分な場合はお勧めしません。 Application.StatusBarを使用して、ステータスバーで。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top