G
gregg5l
Guest
Bonjour à toutes et à tous
J'ai eut beau chercher sur ce forum avant de poster, mais je n'ai pas trouver de solution adéquate.
Voici ce que je veux faire par macro:
Lorsque trois classeurs dont j'ai besoin pour récupérer des données sont ouverts, je copie certaines plages, afin d'exploiter ces données.
La macro que j'ai conçu fonctionne, mais elle n'est pas du plus bel effet car on voit brièvement s'ouvrir les autres classeur et c'est assez laid.
Voici le code de la macro :
Sub PREPA2()
'
' PREPA2 Macro
'
' Touche de raccourci du clavier: Ctrl+w
'
'Sub Test()
Dim wk As Workbook, wl As Workbook, wm As Workbook, bool As Boolean, bool1 As Boolean, bool2 As Boolean
'1er test
For Each wk In Application.Workbooks
If wk.Name = "Preparation.xls" Then bool = True
Next wk
'2eme test
For Each wk In Application.Workbooks
If wk.Name = "026.xls" Then bool1 = True
Next wk
'3eme test
For Each wk In Application.Workbooks
If wk.Name = "029.xls" Then bool2 = True
Next wk
If bool = False Then
MsgBox "Le fichier Preparation.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool1 = False Then
MsgBox "Le fichier 026.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool2 = False Then
MsgBox "Le fichier 029.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool = True And bool1 = True And bool2 = True Then
Windows("Preparation.xls").Activate
Range("A3:I500").Select
Selection.Copy
Windows("produc.xls").Activate
Sheets("PREP").Select
Range("A1").Select
ActiveSheet.Paste
Windows("026.xls").Activate
Range("A3😀50").Select
Application.CutCopyMode = False
Selection.Copy
Windows("produc.xls").Activate
Range("A500").Select
ActiveSheet.Paste
Windows("029.xls").Activate
Range("A3😀40").Select
Application.CutCopyMode = False
Selection.Copy
Windows("produc.xls").Activate
Range("A549").Select
ActiveSheet.Paste
Sheets("PROD").Select
MsgBox "Les données ont été récupérées. Veuillez fermez les feuilles Préparation, 026 et 029 avant de continuer."
Range("A1").Select
End If
End Sub
Merci de votre collaboration.
GREG
J'ai eut beau chercher sur ce forum avant de poster, mais je n'ai pas trouver de solution adéquate.
Voici ce que je veux faire par macro:
Lorsque trois classeurs dont j'ai besoin pour récupérer des données sont ouverts, je copie certaines plages, afin d'exploiter ces données.
La macro que j'ai conçu fonctionne, mais elle n'est pas du plus bel effet car on voit brièvement s'ouvrir les autres classeur et c'est assez laid.
Voici le code de la macro :
Sub PREPA2()
'
' PREPA2 Macro
'
' Touche de raccourci du clavier: Ctrl+w
'
'Sub Test()
Dim wk As Workbook, wl As Workbook, wm As Workbook, bool As Boolean, bool1 As Boolean, bool2 As Boolean
'1er test
For Each wk In Application.Workbooks
If wk.Name = "Preparation.xls" Then bool = True
Next wk
'2eme test
For Each wk In Application.Workbooks
If wk.Name = "026.xls" Then bool1 = True
Next wk
'3eme test
For Each wk In Application.Workbooks
If wk.Name = "029.xls" Then bool2 = True
Next wk
If bool = False Then
MsgBox "Le fichier Preparation.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool1 = False Then
MsgBox "Le fichier 026.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool2 = False Then
MsgBox "Le fichier 029.xls n'est pas ouvert. Ouvrez-le avant de continuer"
End If
If bool = True And bool1 = True And bool2 = True Then
Windows("Preparation.xls").Activate
Range("A3:I500").Select
Selection.Copy
Windows("produc.xls").Activate
Sheets("PREP").Select
Range("A1").Select
ActiveSheet.Paste
Windows("026.xls").Activate
Range("A3😀50").Select
Application.CutCopyMode = False
Selection.Copy
Windows("produc.xls").Activate
Range("A500").Select
ActiveSheet.Paste
Windows("029.xls").Activate
Range("A3😀40").Select
Application.CutCopyMode = False
Selection.Copy
Windows("produc.xls").Activate
Range("A549").Select
ActiveSheet.Paste
Sheets("PROD").Select
MsgBox "Les données ont été récupérées. Veuillez fermez les feuilles Préparation, 026 et 029 avant de continuer."
Range("A1").Select
End If
End Sub
Merci de votre collaboration.
GREG