avyrex1926
Messages postés360Date d'inscriptiondimanche 3 décembre 2006StatutMembreDernière intervention 3 janvier 2012
-
30 août 2007 à 22:02
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 2011
-
31 août 2007 à 00:17
Bonjour à tous,
Dans mon script, je trouve qu'il prend beaucoup de temps à s'exécuter, environ
15 à 20 secondes et je ne sais pas pourquoi.
Y a-t-il moyen d'accélérer l'application reliée au script?
Voici le script:
<hr size="2" width="100%" />Private Sub CommandButton3_Click()
'RECHERCHE D'INFO DANS LE FICHIER EXCEL
msg = "VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?"
Style = vbYesNo + vbDefaultButton1
Réponse = MsgBox(msg, Style, Title)
If Réponse = vbYes Then
Application.ScreenUpdating = False
ComboBox2 = ComboBox1
Sheets(TextBox2.Text).Select
Dim Recherche As Range, Ligne As Long
'colonne C = numéro de commande
Set Recherche = Columns("B:B").Find(ComboBox1)
If Not Recherche Is Nothing Then
Ligne = Recherche.Row
ComboBox10 = Range("E" & Ligne)
ComboBox11 = Range("F" & Ligne)
ComboBox12 = Range("G" & Ligne)
ComboBox13 = Range("H" & Ligne)
ComboBox14 = Range("I" & Ligne)
ComboBox15 = Range("J" & Ligne)
ComboBox16 = Range("K" & Ligne)
relax62
Messages postés82Date d'inscriptionvendredi 2 avril 2004StatutMembreDernière intervention 8 juillet 20121 30 août 2007 à 23:18
Bonsoir,
Difficile à dire,
1)Déjà commencer par déclarer TOUTES les variables .
En effet chaque variable non déclaré est considéré comme Variant (qui prend énormément de mémoire).
ex : msg = "VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?"
Comme nous savons déjà que c'est du texte autant lui dire en déclarant :
dim msg as string
msg = "VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?"
Peut-être que tu ne gagneras pas en vitesse mais en mémoire c'est sur !
Tu peux meme compresser pour aller plus vite:
If MsgBox("VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?", vbYesNo + vbDefaultButton1, "Titre") = vbYes Then
2)Apparemment dans ton code selon les conditions, tu fais appel plusieurs fois à ActiveWorkbook.save
à mon avis, ça doit prendre du temps.
Si tu veux sauvegarder selon certaines conditions, crée une variable du genre:
dim Sauver as boolean
Sauver=False
...
if then
Sauver=true
endif
...
et à la fin
if Sauver then activeworkbook.save
Je n'ai pas excel sur le pc d'ou je te repond donc ne prend pas garde si le code n'est pas tout à fait exact.
mortalino
Messages postés6786Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention21 décembre 201118 30 août 2007 à 23:35
salut Avyrex,
je t'ai quelques petites modifs, mais dans l'ensemble, c'est pas mal ;)
Je ne sais pas si ça va changer le temps d'exécution (si oui, de très peu). En cas, tiens moi au courant :
Private Sub CommandButton3_Click()
Dim bSave As Boolean, i As Long, j As Long
'RECHERCHE D'INFO DANS LE FICHIER EXCEL
'msg = "VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?"
'Style = vbYesNo + vbDefaultButton1
'Réponse = MsgBox("VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?", vbYesNo + vbDefaultButton1, Title)
If MsgBox("VOULEZ-VOUS VRAIMENT ENREGISTER LES CHANGEMENTS?", vbYesNo + vbDefaultButton1, Title) = vbYes Then
Application.ScreenUpdating = False
ComboBox2 = ComboBox1
Sheets(TextBox2.Text).Select
Dim Recherche As Range, Ligne As Long
'colonne C = numéro de commande
Set Recherche = Columns("B:B").Find(ComboBox1)
If Not Recherche Is Nothing Then
Ligne = Recherche.Row
For i = 3 To 9
Me.Controls("Combobox" & i) = Range("D" & Ligne)
Next i
For i = 10 To 16
Me.Controls("Combobox" & i) = Cells(Ligne, i - 5)
Next i
If ComboBox10 = vbNullString Then
ComboBox3 = vbNullString
bSave = True
End If
If ComboBox11 = vbNullString Then
ComboBox4 = vbNullString
bSave = True
End If
If ComboBox12 = vbNullString Then
ComboBox5 = vbNullString
bSave = True
End If
If ComboBox13 = vbNullString Then
ComboBox6 = vbNullString
bSave = True
End If
If ComboBox14 = vbNullString Then
ComboBox7 = vbNullString
bSave = True
End If
If ComboBox15 = vbNullString Then
ComboBox8 = vbNullString
bSave = True
End If
If ComboBox16 = vbNullString Then
ComboBox9 = vbNullString
bSave = True
End If
If bSave Then ActiveWorkbook.Save
Sheets(TextBox1.Text).Select
End If
'ENTRER LES INFO DANS LE FICHIER EXCEL
'colonne C = numéro de commande
Set Recherche = Columns("A:A").Find(ComboBox1)
If Not Recherche Is Nothing Then
Ligne = Recherche.Row
j = 8
For i = 3 To 9
Me.Controls("Combobox" & i) = Cells(Ligne, j)
j = j + 2
Next i
j = 8
For i = 10 To 16
Me.Controls("Combobox" & i) = Cells(Ligne, i - 5)
j = j + 2
Next i
Range("V" & Ligne + 1) = ComboBox2
ActiveWorkbook.Save
End If
Application.ScreenUpdating = True
End Sub