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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| Sub AOP_file_Copy()
'Condition de fonctionnement : les fichiers Resources Plan et AOP file doivent être dans le même dossier
If MsgBox(" => Check that Resources Plan and AOP files are in the same folder", vbOKCancel) = vbOK Then
End If
' Déclaration de variables
filePath = ThisWorkbook.Path
Filename = "Fichier_Cible.xslm"
fileAOPfile = "Fichier_Source.xlsx"
Sheet_Input = "Total"
Sheet_Output = "Destination"
col_ProjectName = 6 ' Car la colonne contenant les noms de projets est la colonne F
last_Col_AOP = 46 ' Car la dernière colonne est la colonne AT
' Fermeture d'un classeur ouvert de même nom : fileMethodsTools
For Each w In Workbooks
If w.Name Like fileAOPfile Then
w.Close savechanges:=False
ElseIf w.Name Like fileResult Then
w.Close savechanges:=True
End If
Next w
' Ouverture et activation de AOPfile
Workbooks.Open (filePath & "\Fichier_Source.xlsx")
Windows("Fichier_Source.xlsx").Activate
Sheets(Sheet_Input).Select
'Déprotéger la feuille
Sheets(Sheet_Input).Unprotect ("ESDIProgram")
'Afficher toutes les colonnes et toutes les lignes masquées
With Sheets(Sheet_Input).Cells
.EntireColumn.Hidden = False
.EntireRow.Hidden = False
End With
' Tous les filtres de la ligne 2 du fichier fileAOPfile sont mis à "Select All"
'nb_Filters_ToBeSelectAll = 2
'max_nb_Filters_ToBeSelectAll = col_Last_Filter - col_Begin_Filter
'Do While nb_Filters_ToBeSelectAll <= max_nb_Filters_ToBeSelectAll
' Cells.AutoFilter Field:=nb_Filters_ToBeSelectAll
' nb_Filters_ToBeSelectAll = nb_Filters_ToBeSelectAll + 1
'Loop
On Error Resume Next
Worksheets(Sheet_Input).ShowAllData
'Sélectionne la dernière ligne complétée
lastRow_Input = Columns(col_ProjectName).Find("*", , , , xlByColumns, xlPrevious).Row
' Copie de la plage de données colonne A to AT des lignes 1 à dernière sélectionnée
Set rng_Select_AOP = Range(Cells(1, col_ProjectName - 5), Cells(lastRow_Input, last_Col_AOP))
With rng_Select_AOP
.Copy
End With
Range("[Fichier_Cible]Destination!A1").PasteSpecial xlPasteAll
' Collage des lignes copiées dans le fichier de résultat
Windows(Filename).Activate
Sheets(Sheet_Output).Select
Cells(1, 1).Select
With ActiveSheet.Paste
End With
' Vide le presse-papier
Application.CutCopyMode = False
' Mettre la date du jour dans la cellule A3 de la feuille "AOPfileCopy"
Range("[Fichier_Cible]Destination!A1").Value = "Date of last copy"
Range("[Fichier_Cible]Destination!C1").Value = Format(Now, "mm/dd/yyyy")
' Cells(1, 1).Value = "Date of last copy"
' Cells(1, 3).Value = Format(Now, "mm/dd/yyyy")
'1 est l'index de la couleur dans la palette des 56 couleurs.
ActiveWorkbook.Colors(1) = RGB(226, 107, 10)
Workbooks("Fichier_Cible.xlsm").Colors(1) = RGB(226, 107, 10)
'Colorie les cellules
Range("[Fichier_Cible]Destination!A1:C1").Interior.ColorIndex = 1
' Cells(1, 1).Interior.ColorIndex = 1
' Cells(1, 2).Interior.ColorIndex = 1
' Cells(1, 3).Interior.ColorIndex = 1
' Mettre la date du jour dans la cellule A3 de la feuille "Extracts"
Range("[Fichier_Cible]Extract!C1").Value = Format(Now, "mm/dd/yyyy")
' Windows(Filename).Activate
' Sheets("Extract").Select
' Cells(1, 3).Value = Format(Now, "mm/dd/yyyy")
' Fermeture de tous les classeurs
For Each w In Workbooks
If w.Name Like fileAOPfile Then
w.Close savechanges:=False
End If
Next w
MsgBox ("AOP file copy is Done")
End Sub |
Partager