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 107 108 109 110 111 112 113 114 115 116 117 118
|
Set MyWbActif = ActiveWorkbook
'on boucle sur les 20 lignes de variable possibles
For i = 2 To 21
'on boucle sur la période souhaitée
Lg = 1
col = 1
Dim XL As New Excel.Application
MyWbActif.Activate
MyWbActif.Sheets("FichiersOK").Select
If i = 2 Then
Sheets("FichiersOK").cells.Select
Selection.ClearContents
End If
MyWbActif.Sheets("Paramètres").Select
If cells(i, 7) = "" Then Exit Sub
variable = MyWbActif.Sheets("Paramètres").cells(i, 6) & " - " & MyWbActif.Sheets("Paramètres").cells(i, 7) & " : "
Application.ScreenUpdating = True
Application.StatusBar = variable
Application.ScreenUpdating = False
Onglet = cells(i, 11)
destination = cells(i, 13)
If Fichier_Existe(destination) = False Then 'si le fichier n'existe pas on le crée
'on teste d'abord si le dossier existe
If Dossier_Existe(cells(i, 9)) = False Then
MsgBox "dossier destination inexistant"
Exit Sub
End If
'création du fichier
Workbooks.Add
Sheets("Feuil1").Select
Sheets("Feuil1").Name = Onglet
ActiveWorkbook.SaveAs Filename:=destination
ActiveWorkbook.Close
End If
'si il existe on l'ouvre
Set MyWbDest = Workbooks.Open(destination)
MyWbDest.Activate 'fichier ouvert, il va falloir récupérer les données pour les traiter
'Fichier = Application.GetOpenFilename("Fichiers Excel (*.xls), *.xls")
With MyWbActif.Sheets("Paramètres")
For aaaa = .cells(i, 2) To .cells(i, 4)
For mm = 1 To 12
If aaaa = .cells(i, 2) And mm < .cells(i, 3) Then mm = .cells(i, 3)
If aaaa = .cells(i, 4) And mm > .cells(i, 5) Then Exit For
If mm < 10 Then mm = "0" & mm
Application.ScreenUpdating = True
Application.StatusBar = variable & " " & aaaa & mm
Application.ScreenUpdating = False
Chemin = .cells(i, 1) & "\" & aaaa & mm & "\" & .cells(i, 6) & "\" & .cells(i, 7)
'on teste d'abord si le dossier existe
If Dossier_Existe(.cells(i, 1) & "\" & aaaa & mm & "\" & .cells(i, 6)) = False Then
'MsgBox "dossier destination inexistant"
MyWbActif.Sheets("FichiersOK").cells(Val(mm) + 13 * (i - 2), col) = aaaa & mm & "\" & .cells(i, 6) & " inexistant"
GoTo suivant
End If
'puis on teste si le fichier existe
If Fichier_Existe(Chemin) = False Then
MyWbActif.Sheets("FichiersOK").cells(Val(mm) + 13 * (i - 2), col) = aaaa & mm & "\" & .cells(i, 6) & "\" & .cells(i, 7) & " inexistant"
GoTo suivant
End If
'puis si l'onglet existe, on continue à la suite donc on ne fait rien, sinon nouvel onglet
If Onglet_Existe(Onglet) = False Then
Sheets.Add.Name = Onglet
End If
Set MyWb = Workbooks.Open(Chemin)
MyWb.Activate 'fichier ouvert, il va falloir récupérer les données pour les traiter
'on sélectionne les données et on les copie
dern = Range("A" & Rows.Count).End(xlUp).Row
Range("a1:a" & dern).Select
Selection.Copy
MyWb.Close SaveChanges:=False
MyWbActif.Sheets("FichiersOK").cells(Val(mm) + 13 * (i - 2), col) = variable & aaaa & mm
MyWbDest.Activate
MyWbDest.Sheets(Onglet).Select
dern = MyWbDest.Sheets(Onglet).Range("A" & Rows.Count).End(xlUp).Row
If dern = 1 Then dern = 0
MyWbDest.Sheets(Onglet).Range("a" & dern + 1).PasteSpecial
suivant:
Next mm
col = col + 1
Next aaaa
End With
MyWbDest.Close SaveChanges:=True
MyWbActif.Activate
Sheets("FichiersOK").Select
Next i |
Partager