Zugriff auf die Statusleiste in einer Statusleiste der Office-Anwendung
-
03-07-2019 - |
Frage
baue ich VBA-Anwendungen für Word und Excel, ist es eine Möglichkeit, die Statusleiste zuzugreifen, die in der Office-Statusleiste angezeigt werden manchmal.
Lösung
Im Folgenden wird ein Fortschrittsbalken in Excel-Statusleiste stimulieren:
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
Andere Tipps
Ich würde aber auch empfehlen, den aktuellen Zustand der Statusleiste aufzunehmen, dann ist es wiederherstellen, wenn alles fertig ist.
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
ich die Fortschrittsbalken nicht zugegriffen haben, aber ich habe in der Vergangenheit verwendet, um etwas wie dieser Aufgabenstatus in der Statusleiste angezeigt wird ...
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, gibt es keine Möglichkeit, die blaue Linie von Punkten von Word & Excel zu zeigen, Fortschritte in Richtung auf 100%, zB beim Öffnen einer Datei verwendet, zu reproduzieren.
Ich erinnere mich einmal etwas Code in der Statusleiste zu replizieren, aber es war komplex, und ich würde es nicht empfehlen, wenn es stattdessen völlig ausreichend ist „X% abgeschlossen“ in der Statusleiste zu sagen, Anwendung mit .StatusBar.