Lut,
En cherchant bien sur la toile ...........
Function CreateProgressBar(Txt$) As Object
Dim BarForm As Object, Lbl As Object, btn As Object, X
'le userform
Set BarForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With BarForm
.Properties("Caption") = Txt
.Properties("Width") = 267
.Properties("Height") = 100
.Properties("ShowModal") = False
End With
'le label pour afficher la progression
Set Lbl = BarForm.designer.Controls.Add("forms.Label.1")
With Lbl
.Left = 24: .Top = 7: .Width = 215: .Height = 15
.BackColor = &HFF8080: .SpecialEffect = 2
.Font.Bold = True: .TextAlign = 2
End With
VBA.UserForms.Add (BarForm.Name)
Set CreateProgressBar = UserForms(UserForms.count - 1)
End Function 'fs
Sub MAJBarre(PB As Object, Inc, Compteur, Max)
If Compteur Mod Inc = 0 Then
With PB
.Label1.Width = CInt(Compteur * 215 / Max)
.Label1.Caption = Format(Compteur / Max, "0%")
.Repaint
End With
End If
End Sub 'fs
Sub DelProgressBar(Nom$)
With ThisWorkbook.VBProject.VBComponents
.Remove .Item(Nom)
End With
End Sub 'fs
'exemple d'utilisation simple :
'à adapter selon ta config
Sub TestPB()
Dim PB As String, i&, j&, Max&
Dim ufBar As Object
'crée la barre de progression et l'affecte à une variable objet
Set ufBar = CreateProgressBar("Test écriture")
ufBar.Show
Max = 5000
For i = 1 To 5000
For j = 1 To 10
'pour faire quelque chose
Cells(i, j).Value = i + j
'mise à jour de la barre de progression
MAJBarre ufBar, 10, i, Max
Next j
Next i
'détruit la barre de progression
'(il faut procéder dans cet ordre)
DelProgressBar ufBar.Name
Unload ufBar
Set ufBar = Nothing
'on efface tout
Cells.ClearContents
MsgBox "Terminé"
End Sub
Cordialement, Jean-Paul
______________________________________________________________________
Le Savoir n'a de valeur que s'il est partagé