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
| Private Sub cbOK_Click()
Dim rConge As Range, trouve As Range
Dim bouton As OLEObject
Set rConge = config.Range("D2:D15")
If cbConfirm.Value = True Then
'création des feuilles de calculs pour chaque mois
Worksheets.Add(After:=Sheets(1)).Name = "Novembre " + tbad.Text
Worksheets.Add(After:=Sheets(2)).Name = "Décembre " + tbad.Text
Worksheets.Add(After:=Sheets(3)).Name = "Janvier " + tbaf.Text
Worksheets.Add(After:=Sheets(4)).Name = "Février " + tbaf.Text
Worksheets.Add(After:=Sheets(5)).Name = "Mars " + tbaf.Text
Worksheets.Add(After:=Sheets(6)).Name = "Avril " + tbaf.Text
'il faut à présent initialiser les contenus de chaque feuille
For i = 2 To Sheets.Count
If Left(Sheets(i).Name, 3) <> "ouv" And Left(Sheets(i).Name, 3) <> "con" Then
' création du bouton
Set bouton = Sheets(i).OLEObjects.Add("Forms.Commandbutton.1")
' assignation des valeurs du bouton
With bouton
.Name = "calcul"
.Left = 150
.Top = 5
.Width = 50
.Height = 25
.Object.Caption = "Calcul"
End With
code = "Private Sub calcul_Click()" & vbCrLf
code = code & "Calcul_Heure (ActiveSheet.Name)" & vbCrLf
code = code & "End Sub" & vbCrLf
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
NextLine = .CountOfLines + 1
.insertlines NextLine, code
End With
Sheets(i).Cells(1, 1).Value = Sheets(i).Name
Sheets(i).Range(Sheets(i).Cells(1, 1), Sheets(i).Cells(1, 4)).Merge
Sheets(i).Range(Sheets(i).Cells(3, 1), Sheets(i).Cells(3, 4)).Merge
Sheets(i).Cells(3, 1).Value = "Sous-totaux"
Dim Dico, d
Dim k As Long
Dim c As Range
With Worksheets("config")
k = 1
Set Dico = CreateObject("Scripting.dictionary")
For Each c In Sheets("config").Range("B2:B" & .Range("B" & .Rows.Count).End(xlUp).Row)
If Not Dico.Exists(c.Value) Then Dico.Add c.Value, c.Offset(0, -1).Value
Next c
For Each d In Dico.keys
Sheets(i).Cells(4, k) = d
k = k + 1
Next d
Set Dico = Nothing
End With
' en x,1 il faut placer les noms des ouvriers
j = 2
While Not IsEmpty(ouvriers.Cells(j, 1).Value)
With Sheets(i).Cells(j + 2, 5)
.Value = ouvriers.Cells(j, 1).Value
.Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
.Borders(xlEdgeRight).Weight = xlThick
End With
j = j + 1
Wend
' en 2,x il faut placer les dates
Dim maDate As Date
cell1 = Left(Sheets(i).Cells(1, 1).Value, 3)
annee = Right(Sheets(i).Cells(1, 1).Value, 4)
mois = 0
Select Case cell1
Case "Nov": mois = 11
Case "Déc": mois = 12
Case "Jan": mois = 1
Case "Fév": mois = 2
Case "Mar": mois = 3
Case "Avr": mois = 4
End Select
maDate = CDate("01/" & mois & "/" & annee)
maDate = DateAdd("m", 1, maDate)
maDate = DateAdd("d", -1, maDate)
compteur = 6
For j = 1 To Day(maDate)
Dim dateJour As Date
dateJour = CDate(j & "/" & mois & "/" & annee)
Set trouve = rConge.Find(what:=dateJour)
' place la date du jour dans la cellule correspondante (ligne 2)
Sheets(i).Cells(2, compteur).Value = WeekdayName(Weekday(dateJour, 2)) & " " & j
If trouve Is Nothing Then
' Si samedi ou dimanche, pas de fusion de cellule
If Weekday(dateJour) = 1 Or Weekday(dateJour) = 7 Then
Sheets(i).Cells(2, compteur).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Cells(2, compteur).Borders(xlEdgeRight).Weight = xlThick
Sheets(i).Cells(3, compteur).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Cells(3, compteur).Borders(xlEdgeRight).Weight = xlThick
Sheets(i).Range(Sheets(i).Cells(3, compteur), Sheets(i).Cells(24, compteur)).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Range(Sheets(i).Cells(3, compteur), Sheets(i).Cells(24, compteur)).Borders(xlEdgeRight).Weight = xlThick
compteur = compteur + 1
' si un jour de semaine normal, fusion des cellules (nombres de tranches horaires)
Else
Sheets(i).Range(Sheets(i).Cells(2, compteur), Sheets(i).Cells(2, compteur + 3)).Merge
' Mise en forme de la cellule de la date
Sheets(i).Cells(2, compteur).HorizontalAlignment = xlCenter
Sheets(i).Cells(2, compteur + 3).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Cells(2, compteur + 3).Borders(xlEdgeRight).Weight = xlThick
' insertion des tranches horaires dans les cellules correspondantes
Sheets(i).Cells(3, compteur + 0).Value = config.Cells(2, 1).Value
Sheets(i).Cells(3, compteur + 1).Value = config.Cells(3, 1).Value
Sheets(i).Cells(3, compteur + 2).Value = config.Cells(4, 1).Value
Sheets(i).Cells(3, compteur + 3).Value = config.Cells(5, 1).Value
Sheets(i).Range(Sheets(i).Cells(3, compteur + 3), Sheets(i).Cells(24, compteur + 3)).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Range(Sheets(i).Cells(3, compteur + 3), Sheets(i).Cells(24, compteur + 3)).Borders(xlEdgeRight).Weight = xlThick
compteur = compteur + 4
End If
' nous sommes un jour férié (spécifié dans la feuille config)
Else
Sheets(i).Cells(3, compteur).Value = "Férié"
Sheets(i).Cells(2, compteur).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Cells(2, compteur).Borders(xlEdgeRight).Weight = xlThick
Sheets(i).Cells(3, compteur).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Cells(3, compteur).Borders(xlEdgeRight).Weight = xlThick
Sheets(i).Range(Sheets(i).Cells(3, compteur), Sheets(i).Cells(24, compteur)).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Sheets(i).Range(Sheets(i).Cells(3, compteur), Sheets(i).Cells(24, compteur)).Borders(xlEdgeRight).Weight = xlThick
compteur = compteur + 1
End If
Next
' indique que les cellules ajuste la largeur automatiquement
Sheets(i).Columns.AutoFit
' spécifie le format "hh:mm" pour les cellules contenant les heures
Sheets(i).Range("A5:D25").NumberFormat = "hh:mm"
Sheets(i).Range("F4:DB25").NumberFormat = "hh:mm"
End If
Next
'activation de la feuille de calcul Accueil
Sheets(1).Activate
'fermeture et déchargement de la boite de dialogue
UFInitialize.Hide
Unload UFInitialize
End If
End Sub |
Partager