Acessando a barra de progresso na barra de status de um aplicativo do Office
-
03-07-2019 - |
Pergunta
Eu crio aplicativos VBA para o Word e Excel, existe alguma maneira de acessar a barra de progresso que às vezes aparece no escritório de status bar.
Solução
A seguir irá simular uma barra de progresso na barra de status do 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
Outras dicas
Eu recomendaria além disso, para gravar o estado atual do StatusBar, em seguida, restaurá-lo quando tudo está feito.
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
Eu não acessou a barra de progresso, mas eu tenho no passado algo usado como este para colocar o texto status da tarefa na barra de status ...
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, não há nenhuma maneira de reproduzir a linha azul de pontos usados ??pelo Word e Excel para mostrar o progresso no sentido de 100%, por exemplo, ao abrir um arquivo.
Lembro-me de uma vez ter visto algum código para replicá-lo na barra de status, mas era complexo, e eu não recomendo, quando é bastante suficiente, em vez de dizer "X% completo" na barra de status, usando o Application .StatusBar.