Le contrôle ProgressBar, version 6.0.
Ce contrôle permet d'afficher par exemple, la progression d'une mise à
1 - Activer un UserForm dans le Visual Basic Editor.
La boîte à outils
Code lié à la macro UpdateProgressBar
jour de cellules (ex. multiplier une plage par un coëfficient).
Exemple trouvé sur le site de Ole P. Erlandsen
2 - Faites un clic droit sur la boîte à outils et sélectionnez Contrôles
supplémentaires.
3 - Dans la liste déroulante, sélectionnez Microsoft ProgressBar Control,
version 6.0.
4 - Cliquez sur OK pour fermer la boîte de dialogue et ajoutez le contrôle
dans la boîte à outils.
Code lançant l'indicateur de progression
' Displays a progress bar while a macro runs, requires a reference to MSCOMCTRL.OCX
Dim lngTotal As Long, lngI As Long
' Initiate ProgressBar
Load frmProgressBar
With frmProgressBar
.ProgressBar.Scrolling = ccScrollingStandard ' or ccScrollingSmooth
.Show ' set the UserForms ShowModal property to false before running
' or .Show False
End With
UpdateProgressBar 0, "Processing..." ' set initial progress status
' start the process
lngTotal = 2000
For lngI = 1 To lngTotal
If lngI Mod 50 = 0 Then ' Update the ProgressBar for every 50th loop
UpdateProgressBar lngI / lngTotal * 100, "Processing " & Format _
(lngI / lngTotal, "0%") & "..."
End If
' Do something, place your code here
Range("D1").Formula = Format(Time, "hh:mm:ss")
Next lngI
Range("D1").ClearContents
' Clean up
frmProgressBar.Hide
Unload frmProgressBar
End Sub
' Updates the progressbar dialog
With frmProgressBar
If Not IsMissing(NewCaption) Then .Caption = NewCaption
.ProgressBar.Value = NewValue
If NewValue = 0 Then .Repaint
End With
End Sub