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
|
Option Explicit
Sub GenererLesCalendriers()
Dim J As Integer
Application.ScreenUpdating = False
For J = 1 To 12
CreationCalendriersMensuels J
Next J
Application.ScreenUpdating = True
End Sub
Sub CreationCalendriersMensuels(ByVal MoisACreer As Integer)
Dim ShMois As Worksheet
Dim I As Integer, MoisEnCours As Integer, LigneEncours As Integer, DerniereLigne As Integer
Dim DatesEnCours As Date
Dim AireJours As Range
MoisEnCours = MoisACreer
Sheets("Modèle").Copy after:=Sheets(Sheets.Count)
Set ShMois = ActiveSheet
With ShMois
Set AireJours = .Range(.Cells(2, 1), .Cells(30, 1))
AireJours.Clear
LigneEncours = 0
For DatesEnCours = CDate("01/01/" & Year(Date)) To CDate("31/12/" & Year(Date))
If Month(DatesEnCours) = MoisEnCours Then
Select Case WorksheetFunction.Weekday(DatesEnCours, 2)
Case 1 To 5
If LigneEncours = 0 Then
LigneEncours = 1 + WorksheetFunction.Weekday(DatesEnCours, 2)
End If
With .Cells(LigneEncours, 1)
.Value = Format(DatesEnCours, "dd/mm/yyyy dddd")
If TypeJour(DatesEnCours) = 2 Then
.Interior.Color = RGB(255, 255, 0)
End If
End With
LigneEncours = LigneEncours + 1
Case 6
If LigneEncours > 2 Then
With .Cells(LigneEncours, 1)
.Value = "TOTAL"
.Font.Bold = True
End With
LigneEncours = LigneEncours + 1
End If
End Select
End If
Next DatesEnCours
For I = AireJours.Count To 1 Step -1
With AireJours(I)
Select Case .Value
Case ""
.Offset(0, 1).ClearContents
' .EntireRow.Hidden = True ' Pour masquer les lignes vides
Case "TOTAL"
Case Else
If .Interior.Color = RGB(255, 255, 0) Then
.Offset(0, 1).ClearContents
Else
.Offset(0, 1) = 1
End If
End Select
End With
Next I
End With
Set AireJours = Nothing
Set ShMois = Nothing
End Sub
'Cette fonction renvoie 0 si le jour passé en paramètre est un jour de semaine,
'1 s'il s'agit d'un samedi ou d'un dimanche et 2 s'il s'agit d'un jour férié.
'Valide jusqu'en 2099 et pour les jours fériés français
Function TypeJour(D As Date)
'L. Longre
Dim A As Integer, T As Integer
Dim LP As Date, LD As Long
A = Year(D)
If A > 2099 Then
TypeJour = CVErr(xlErrValue)
Exit Function
End If
LD = Int(D)
If LD <= 2 Then
If LD = 1 Then TypeJour = 2
Exit Function
End If
T = (((255 - 11 * (A Mod 19)) - 21) Mod 30) + 21
LP = DateSerial(A, 3, 2) + T + (T > 48) _
+ 6 - ((A + A \ 4 + T + (T > 48) + 1) Mod 7)
Select Case D
' Jours fériés mobiles
Case Is = LP, Is = LP + 38, Is = LP + 49
TypeJour = 2
' Jours fériés fixes
Case Is = DateSerial(A, 1, 1), Is = DateSerial(A, 5, 1), _
Is = DateSerial(A, 5, 8), Is = DateSerial(A, 7, 14), _
Is = DateSerial(A, 8, 15), Is = DateSerial(A, 11, 1), _
Is = DateSerial(A, 11, 11), Is = DateSerial(A, 12, 25)
TypeJour = 2
Case Else
' Samedi ou dimanche
If Weekday(D, vbMonday) >= 6 Then TypeJour = 1
End Select
End Function |
Partager