2008-10-20 7 views

Répondre

4

Voici simulera une barre de progression dans la barre d'état d'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 
0

Je n'ai pas accédé à la barre de progression, mais j'ai utilisé dans le passé quelque chose comme ceci pour placer la tâche texte d'état dans la barre d'état ...

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 
2

Je recommande en outre, pour enregistrer la état actuel du StatusBar, puis le restaurer quand tout est fait.

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 
0

AFAIK, il n'y a aucun moyen de reproduire la ligne bleue de points utilisés par Word Excel & pour montrer les progrès 100%, par exemple lors de l'ouverture d'un fichier. Je me souviens d'avoir vu du code pour le répliquer dans la barre d'état, mais c'était complexe, et je ne le recommanderais pas, quand il suffirait de dire "X% complete" dans la barre d'état, en utilisant Application.StatusBar.

Questions connexes