S
sylvain
Guest
bonjour le forum,
J'aimerais insérer un message d'alerte dans une listbox dans le cas où l'utilisateur ne sélectionne pas de fichier. Pour cela, j'ai créer une condition mais je ne comprends pas, elle ne marche pas : le code concernant cette condition s'exécute tout le temps : trop bizarre. Voici le code ci dessous (en couleur pour le code qui ne marche pas)
merci du coup de main
sylvain
code :
Private Sub CommandButton1_Click()
Dim f As String
Dim i As Integer
If ListBox1.Selected(i) = False Then
MsgBox 'Veuillez choisir une sauvegarde avant de valider'
Exit Sub ' si tu veux arreter le déroulement de la macro
End If
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then f = ListBox1.List(i)
Next i
p = 'c:\\simoporc\\sauvegarde\\'
'f = 'sauvegarde.xls'
s = 'bdd'
u = 'bdd2'
T = 'bdd3'
v = 'bdd4'
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, s, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 2
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd2').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, u, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 4
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd3').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, T, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 6
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd4').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, v, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 8
DoEvents
End With
Unload Me
Worksheets('menu').Cells(15, 7).Value = 1
Call macromodifier
MsgBox ('L'opération s'est terminée avec succès')
End Sub
J'aimerais insérer un message d'alerte dans une listbox dans le cas où l'utilisateur ne sélectionne pas de fichier. Pour cela, j'ai créer une condition mais je ne comprends pas, elle ne marche pas : le code concernant cette condition s'exécute tout le temps : trop bizarre. Voici le code ci dessous (en couleur pour le code qui ne marche pas)
merci du coup de main
sylvain
code :
Private Sub CommandButton1_Click()
Dim f As String
Dim i As Integer
If ListBox1.Selected(i) = False Then
MsgBox 'Veuillez choisir une sauvegarde avant de valider'
Exit Sub ' si tu veux arreter le déroulement de la macro
End If
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then f = ListBox1.List(i)
Next i
p = 'c:\\simoporc\\sauvegarde\\'
'f = 'sauvegarde.xls'
s = 'bdd'
u = 'bdd2'
T = 'bdd3'
v = 'bdd4'
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, s, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 2
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd2').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, u, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 4
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd3').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, T, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 6
DoEvents
End With
With UserForm1.ProgressBar1
.Visible = True
.Min = 0
.Max = 8
Application.ScreenUpdating = False
Sheets('bdd4').Activate
For r = 5 To 11
For c = 3 To 256
a = Cells(r, c).Address
Cells(r, c) = RecupValeur(p, f, v, a)
Next c
Next r
Application.ScreenUpdating = True
Sheets('menu').Activate
.Value = 8
DoEvents
End With
Unload Me
Worksheets('menu').Cells(15, 7).Value = 1
Call macromodifier
MsgBox ('L'opération s'est terminée avec succès')
End Sub