Bonjour à tous,

J'ai un pb et je ne trouve pas de solution...

Explication :
lorsque je lance ma macro (voir après) dans "microsoft VBA" (la console VBA) elle fait son action sur excel en 14 sec (je vois "travailler" excel en parallèle). Mais quand je la lance à partir d'excel avec un bouton : elle prends plus de 3x le temps !!!

Je ne suis pas programmateur, mais j'ai l'habitude des macros et ça m'arrive uniquement avec cette macro ?!?.

j'ai essayé avec ce qui suit en début de macro mais pas d'amélioration :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Application.ScreenUpdating = False 'Arrête certains calculs automatiques
Application.EnableEvents = False ' => désactive les événements

Donc merci de vos idées par avance. je suis sec

Voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Sub recuperer_dataactuellecomplet()
On Error GoTo ErrorHandler
'Application.ScreenUpdating = False 'Arrête certains calculs automatiques
'Application.EnableEvents = False ' => désactive les événements
'cette macro va ecrire tous les fichiers !!! eviter de l'utiliser !!!
 
Dim col_1_plan, col_fin_plan, lig_1_plan, lig_fin_plan
Dim repert As String
Dim inc_l, inc_col
Dim fic As String
Dim nom_fichier
Dim tabl(8) 'tableau pour transfert des données
 
'lectures des variables
lig_1_plan = Sheets("data_macro").Range("B12")
col_1_plan = Sheets("data_macro").Range("B13")
lig_fin_plan = Sheets("data_macro").Range("B14")
col_fin_plan = Sheets("data_macro").Range("B15")
repert = Sheets("data_macro").Range("B10")
 
'déclaration variables incrémentation
inc_l = lig_1_plan
 
 
 
While inc_l <= lig_fin_plan
    inc_col = col_1_plan 'déclaration variables incrémentation
 
    While inc_col <= col_fin_plan
        nom_fichier = inc_l * 10000 + inc_col
        fic = repert & nom_fichier & ".csv"
 
        Open fic For Input As #1 'lecture
        Line Input #1, tabl(1)
        Line Input #1, tabl(2)
        Line Input #1, tabl(3)
        Line Input #1, tabl(4)
 
        Close #1
 
        Sheets("Feuil1").Cells(inc_l, inc_col) = tabl(1) 'ecriture
        Sheets("Feuil1").Cells(inc_l, inc_col + 1) = tabl(2)
        Sheets("Feuil1").Cells(inc_l, inc_col + 2) = tabl(3)
        Sheets("Feuil1").Cells(inc_l, inc_col + 3) = tabl(4)
 
        inc_col = inc_col + 4
    Wend 'inc_col
 
    inc_l = inc_l + 1
 
Wend 'inc_l
MsgBox "Terminé avec succès"
 
'Application.ScreenUpdating = True 'Réactive les calculs.
'Application.EnableEvents = True ' => réactive les événements
    Exit Sub
ErrorHandler:
    'Le code qui s'execute si il y a une erreur
 
    Dim MonResultat
    MonResultat = MsgBox("Une erreur s'est produite. numéro fichier : " & nom_fichier & "   , contacter P" & vbCrLf & vbCrLf & "Erreur n° " & Err.Number & vbCrLf & "Description : " & Err.Description, vbCritical + vbOKOnly, "Erreur d'execution")
 
End Sub