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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| Sub test2()
Dim MyPath As Variant
Dim LaDatedeb As Date
Dim LaDatefin As Date
Dim NomRep As String
Dim LaDate As Date
Dim y As Variant
Dim JourS As Variant
LaDate = DateSerial(Range("C4"), Range("B4"), Range("A4"))
LaDatedeb = DateSerial(Range("C4"), Range("B4"), Range("A4"))
LaDatefin = DateSerial(Range("C5"), Range("B5"), Range("A5"))
JourS = Day(LaDate)
NomRep = Format(LaDate, "dd_mm_yy") & ""
MsgBox NomRep
MyPath = "F:\Pilotes\" & [NomRep] & ""
MsgBox MyPath
'For LaDate = LaDatedeb To LaDatefin
Do Until LaDatefin < LaDatedeb
If Dir([MyPath], vbDirectory) = " " Then
'si le répertoire n'existe pas
MsgBox "Le répertoire n'existe pas"
LaDate = LaDate + 1
ChDir (MyPath)
' si le répertoire existe et que la date du répertoire est inférieure à la date de fin demandée
'MsgBox MyPath
Else
Workbooks.Open Filename:="F:\Pilotes\" & [NomRep] & "\toto.xls"
'Ouvrir le fichier toto
Sheets("General").Activate
' Activer la feuille général du fichier mobifil
MsgBox "fichier toto ouvert"
'If LaDatefin < LaDatedeb And LaDatefin > Workbooks("monfichier.xlsm").Sheets("feuil1").Range("D10") Then
'si la date fin demandée est inférieure à la date de départ et que la date de fin demandée est supérieure à la date du jour
'MsgBox "Date incorrect"
'If DIR([MyPath], vbDirectory) = " " Then
' si le répertoire existe et que la date du répertoire est inférieure à la date de fin demandée
'MsgBox MyPath
If JourS = 1 Then 'lundi
'If Sheets("General").Cells(8, 3) = "7:00-7:15" Then
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("toto.xls").Activate
ActiveWindow.Close
Else
If JourS = 2 Then 'Mardi
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("toto.xls").Activate
ActiveWindow.Close
If Dir([MyPath], vbDirectory) = " " Then
Else
If JourS = 3 Then 'Mercredi
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("toto.xls").Activate
ActiveWindow.Close
Else
If JourS = 4 Then 'Jeudi
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("toto.xls").Activate
ActiveWindow.Close
Else
If JourS = 5 Then 'Vendredi
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("toto.xls").Activate
ActiveWindow.Close
Else
If JourS = 6 Then 'Samedi
Range("C8:C39,C52:C67").Select
Selection.Copy
Windows("monfichier.xlsm").Activate
Sheets("LUNDI").Select
Range("C7").Select
ActiveSheet.Paste
Range("D12").Select
Windows("totol.xls").Activate
ActiveWindow.Close
End If
End If
End If
End If
End If
End If
End If
Workbooks("toto.xls").Close
End If
LaDate = LaDate + 1
ChDir (MyPath)
MsgBox "fin d'essai"
Loop
End Sub |
Partager