Dim wsSaisie As Worksheet
Dim wsDoc As Worksheet
Dim wsListe As Worksheet
Set wsSaisie = ThisWorkbook.Sheets("Saisie")
Set wsDoc = ThisWorkbook.Sheets("Document")
Set wsListe = ThisWorkbook.Sheets("Liste")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim ligneDepart As Long
ligneDepart = 17
Dim colDepart As Long
colDepart = 2
' Constantes
Const NB_QH As Long = 96
Const COL_FIN As Long = 98
Const DECALAGE_FIN As Long = 6
' Largeur colonnes fixes
wsDoc.Columns(colDepart).ColumnWidth = 22
wsDoc.Columns(colDepart + 1).ColumnWidth = 8
' Nettoyage contenu
wsDoc.Rows(ligneDepart & ":" & wsDoc.Rows.Count).ClearContents
wsDoc.Rows(ligneDepart & ":" & wsDoc.Rows.Count).ClearFormats
' Suppression shapes générées
Dim i As Long
For i = wsDoc.Shapes.Count To 1 Step -1
Dim sType As Integer
sType = wsDoc.Shapes(i).Type
If sType = 17 Or sType = 1 Or sType = 9 Then ' msoTextBox=17, msoLine=9, msoConnector=1... on garde images=13
wsDoc.Shapes(i).Delete
End If
Next i
' -- EN-TÊTE --
wsDoc.Rows(ligneDepart).RowHeight = 20
wsDoc.Rows(ligneDepart + 1).RowHeight = 20
wsDoc.Rows(ligneDepart + 2).RowHeight = 20
wsDoc.Rows(ligneDepart + 3).RowHeight = 20
wsDoc.Rows(ligneDepart + 4).RowHeight = 25
' Fusion "Gares"
wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart), wsDoc.Cells(ligneDepart + 4, colDepart)).Merge
wsDoc.Cells(ligneDepart, colDepart).Value = "Gares"
wsDoc.Cells(ligneDepart, colDepart).Font.Name = "Arial"
wsDoc.Cells(ligneDepart, colDepart).Font.Size = 17
wsDoc.Cells(ligneDepart, colDepart).Font.Bold = True
wsDoc.Cells(ligneDepart, colDepart).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneDepart, colDepart).VerticalAlignment = xlCenter
' Fusion "Régime"
wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart + 1), wsDoc.Cells(ligneDepart + 4, colDepart + 1)).Merge
' Fusion "Périodes d'ouverture"
wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart + 2), wsDoc.Cells(ligneDepart + 3, colDepart + 68)).Merge
wsDoc.Cells(ligneDepart, colDepart + 2).Value = "Périodes d'ouverture"
wsDoc.Cells(ligneDepart, colDepart + 2).Font.Name = "Arial"
wsDoc.Cells(ligneDepart, colDepart + 2).Font.Size = 17
wsDoc.Cells(ligneDepart, colDepart + 2).Font.Bold = True
wsDoc.Cells(ligneDepart, colDepart + 2).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneDepart, colDepart + 2).VerticalAlignment = xlCenter
' Heures 0 à 23
Dim hh As Long
For hh = 0 To 23
Dim colHH As Long
colHH = (hh * 4) + colDepart + 2
wsDoc.Range(wsDoc.Cells(ligneDepart + 4, colHH), wsDoc.Cells(ligneDepart + 4, colHH + 3)).Merge
wsDoc.Cells(ligneDepart + 4, colHH).Value = hh
wsDoc.Cells(ligneDepart + 4, colHH).Font.Bold = True
wsDoc.Cells(ligneDepart + 4, colHH).Font.Color = RGB(0, 112, 192)
wsDoc.Cells(ligneDepart + 4, colHH).Font.Size = 15
wsDoc.Cells(ligneDepart + 4, colHH).HorizontalAlignment = xlCenter
Next hh
' Largeur colonnes horaires
Dim c As Long
For c = colDepart + 2 To colDepart + COL_FIN
wsDoc.Columns(c).ColumnWidth = 1.2
Next c
' -- LÉGENDE --
wsDoc.Range(wsDoc.Cells(ligneDepart + 1, colDepart + 69), wsDoc.Cells(ligneDepart + 1, colDepart + 73)).Merge
wsDoc.Cells(ligneDepart + 1, colDepart + 69).Interior.Color = RGB(31, 73, 125)
wsDoc.Range(wsDoc.Cells(ligneDepart + 1, colDepart + 74), wsDoc.Cells(ligneDepart + 1, colDepart + COL_FIN)).Merge
wsDoc.Cells(ligneDepart + 1, colDepart + 74).Value = "Gare permanente"
wsDoc.Cells(ligneDepart + 1, colDepart + 74).Font.Color = RGB(0, 112, 192)
wsDoc.Cells(ligneDepart + 1, colDepart + 74).Font.Bold = True
wsDoc.Cells(ligneDepart + 1, colDepart + 74).Font.Size = 13
wsDoc.Cells(ligneDepart + 1, colDepart + 74).VerticalAlignment = xlCenter
wsDoc.Range(wsDoc.Cells(ligneDepart + 2, colDepart + 69), wsDoc.Cells(ligneDepart + 2, colDepart + 73)).Merge
wsDoc.Cells(ligneDepart + 2, colDepart + 69).Interior.Color = RGB(149, 179, 215)
wsDoc.Range(wsDoc.Cells(ligneDepart + 2, colDepart + 74), wsDoc.Cells(ligneDepart + 2, colDepart + COL_FIN)).Merge
wsDoc.Cells(ligneDepart + 2, colDepart + 74).Value = "Gare temporaire"
wsDoc.Cells(ligneDepart + 2, colDepart + 74).Font.Color = RGB(0, 112, 192)
wsDoc.Cells(ligneDepart + 2, colDepart + 74).Font.Size = 13
wsDoc.Cells(ligneDepart + 2, colDepart + 74).VerticalAlignment = xlCenter
' -- BORDURES EN-TÊTE --
Dim rngTableau As Range
Set rngTableau = wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart), wsDoc.Cells(ligneDepart + 4, colDepart + COL_FIN))
With rngTableau.Borders(xlEdgeTop)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With rngTableau.Borders(xlEdgeBottom)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With rngTableau.Borders(xlEdgeLeft)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With rngTableau.Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart), wsDoc.Cells(ligneDepart + 4, colDepart)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart + 1), wsDoc.Cells(ligneDepart + 4, colDepart + 1)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDepart + 4, colDepart), wsDoc.Cells(ligneDepart + 4, colDepart + COL_FIN)).Borders(xlEdgeTop)
.LineStyle = xlContinuous: .Weight = xlThin: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDepart + 4, colDepart), wsDoc.Cells(ligneDepart + 4, colDepart + COL_FIN)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
' -- BOUCLE --
Dim ligneSelectionnee As String
ligneSelectionnee = wsSaisie.Cells(10, 3).Value
Dim ligneSource As Long
Dim ligneDoc As Long
ligneSource = 2
ligneDoc = ligneDepart + 5
Do While wsListe.Cells(ligneSource, 7).Value <> ""
If wsListe.Cells(ligneSource, 7).Value = ligneSelectionnee Then
Dim ligneB As Long
ligneB = ligneDoc + 1
wsDoc.Rows(ligneDoc).RowHeight = 15
wsDoc.Rows(ligneB).RowHeight = 40
wsDoc.Rows(ligneDoc + 2).RowHeight = 15
' Fusion gare et régime
wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart), wsDoc.Cells(ligneDoc + 2, colDepart)).Merge
wsDoc.Cells(ligneDoc, colDepart).Value = wsListe.Cells(ligneSource, 8).Value
wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart + 1), wsDoc.Cells(ligneDoc + 2, colDepart + 1)).Merge
wsDoc.Cells(ligneDoc, colDepart + 1).Value = wsListe.Cells(ligneSource, 9).Value
' Typographie gare
wsDoc.Cells(ligneDoc, colDepart).Font.Name = "Arial"
wsDoc.Cells(ligneDoc, colDepart).Font.Size = 17
wsDoc.Cells(ligneDoc, colDepart).Font.Color = RGB(0, 112, 192)
wsDoc.Cells(ligneDoc, colDepart).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneDoc, colDepart).VerticalAlignment = xlCenter
wsDoc.Cells(ligneDoc, colDepart).WrapText = True
Dim nomGare As String
Dim nomLigne As String
nomGare = wsListe.Cells(ligneSource, 8).Value
nomLigne = wsListe.Cells(ligneSource, 7).Value
If InStr(nomLigne, nomGare) > 0 Then
wsDoc.Cells(ligneDoc, colDepart).Font.Bold = True
wsDoc.Cells(ligneDoc, colDepart).Font.Italic = False
Else
wsDoc.Cells(ligneDoc, colDepart).Font.Bold = False
wsDoc.Cells(ligneDoc, colDepart).Font.Italic = True
End If
' Typographie régime
wsDoc.Cells(ligneDoc, colDepart + 1).WrapText = True
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Name = "Arial"
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Size = 14
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Bold = True
wsDoc.Cells(ligneDoc, colDepart + 1).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneDoc, colDepart + 1).VerticalAlignment = xlCenter
' Récupération des infos
Dim debut As Double
Dim Fin As Double
Dim statut As String
Dim couleur As Long
Dim col As Long
Dim heureCol As Double
debut = wsListe.Cells(ligneSource, 10).Value
Fin = wsListe.Cells(ligneSource, 11).Value
statut = wsListe.Cells(ligneSource, 12).Value
Dim debutMod As Variant
Dim finMod As Variant
Dim fermetureExc As String
debutMod = wsListe.Cells(ligneSource, 13).Value
finMod = wsListe.Cells(ligneSource, 14).Value
fermetureExc = wsListe.Cells(ligneSource, 17).Value
Dim affichageNormal As Boolean
affichageNormal = (Trim(fermetureExc) <> "Oui" And debutMod = "" And finMod = "")
' Bordures ligne
Dim rngLigne As Range
Set rngLigne = wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart), wsDoc.Cells(ligneDoc, colDepart + COL_FIN))
With rngLigne.Borders(xlEdgeTop)
.LineStyle = xlContinuous: .Color = RGB(0, 0, 0): .Weight = xlThin
End With
With rngLigne.Borders(xlEdgeLeft)
.LineStyle = xlContinuous: .Color = RGB(0, 0, 0): .Weight = xlThin
End With
With rngLigne.Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Color = RGB(0, 0, 0): .Weight = xlThin
End With
Dim rngLigneC As Range
Set rngLigneC = wsDoc.Range(wsDoc.Cells(ligneDoc + 2, colDepart), wsDoc.Cells(ligneDoc + 2, colDepart + COL_FIN))
With rngLigneC.Borders(xlEdgeBottom)
.LineStyle = xlContinuous: .Color = RGB(0, 0, 0): .Weight = xlThin
End With
With wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart), wsDoc.Cells(ligneDoc + 2, colDepart)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart + 1), wsDoc.Cells(ligneDoc + 2, colDepart + 1)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
' -- CAS 1 : GARE NORMALEMENT FERMÉE --
If statut = "FERME" Then
If debutMod <> "" And finMod <> "" Then
couleur = RGB(149, 179, 215)
For col = colDepart + 2 To colDepart + COL_FIN
heureCol = (col - colDepart - 2) / 96
If heureCol >= CDbl(debutMod) And heureCol < CDbl(finMod) Then
wsDoc.Cells(ligneB, col).Interior.Color = couleur
End If
Next col
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Color = RGB(255, 0, 0)
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Bold = True
Dim colModDebutF As Long
Dim colModFinF As Long
colModDebutF = Int(CDbl(debutMod) * 96) + colDepart + 2
colModFinF = Int(CDbl(finMod) * 96) + colDepart + 0
Dim shpTraitF As Shape
Dim xDebutF As Double
Dim xFinF As Double
Dim yTraitF As Double
xDebutF = wsDoc.Cells(ligneB, colModDebutF).Left
xFinF = wsDoc.Cells(ligneB, colModFinF).Left
yTraitF = wsDoc.Cells(ligneB, colModDebutF).Top + 35
Set shpTraitF = wsDoc.Shapes.AddConnector(msoConnectorStraight, xDebutF, yTraitF, xFinF, yTraitF)
shpTraitF.Line.ForeColor.RGB = RGB(255, 0, 0)
shpTraitF.Line.Weight = 4
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colModDebutF), CDbl(debutMod), RGB(255, 0, 0), True
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colModFinF - DECALAGE_FIN), CDbl(finMod), RGB(255, 0, 0), True
Else
wsDoc.Range(wsDoc.Cells(ligneB, colDepart + 2), wsDoc.Cells(ligneB, colDepart + COL_FIN)).Merge
wsDoc.Cells(ligneB, colDepart + 2).Value = "Établissement normalement fermé au service de la circulation"
wsDoc.Cells(ligneB, colDepart + 2).Font.Color = RGB(0, 112, 192)
wsDoc.Cells(ligneB, colDepart + 2).Font.Italic = True
wsDoc.Cells(ligneB, colDepart + 2).Font.Size = 16
wsDoc.Cells(ligneB, colDepart + 2).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneB, colDepart + 2).VerticalAlignment = xlCenter
End If
' -- CAS 2 : GARE OUVERTE --
Else
If statut = "PERMANENT" Then
couleur = RGB(31, 73, 125)
ElseIf statut = "TEMPORAIRE" Then
couleur = RGB(149, 179, 215)
End If
For col = colDepart + 2 To colDepart + COL_FIN
heureCol = (col - colDepart - 2) / 96
If heureCol >= debut And heureCol < Fin Then
wsDoc.Cells(ligneB, col).Interior.Color = couleur
End If
Next col
Dim colHeureDebut As Long
Dim colHeureFin As Long
colHeureDebut = Int(debut * 96) + colDepart + 2
colHeureFin = Int(Fin * 96) + colDepart + 2
If debut > 0 And Fin < 1 And affichageNormal Then
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colHeureDebut), debut, RGB(0, 112, 192), False
End If
If Fin < 1 And debut > 0 And affichageNormal Then
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colHeureFin - DECALAGE_FIN), Fin, RGB(0, 112, 192), False
End If
If Trim(fermetureExc) = "Oui" Then
For col = colDepart + 2 To colDepart + COL_FIN
wsDoc.Cells(ligneB, col).Interior.ColorIndex = xlNone
Next col
wsDoc.Range(wsDoc.Cells(ligneB, colDepart + 2), wsDoc.Cells(ligneB, colDepart + COL_FIN)).Merge
wsDoc.Cells(ligneB, colDepart + 2).Value = "Établissement exceptionnellement fermé au service de la circulation"
wsDoc.Cells(ligneB, colDepart + 2).Font.Color = RGB(255, 0, 0)
wsDoc.Cells(ligneB, colDepart + 2).Font.Bold = True
wsDoc.Cells(ligneB, colDepart + 2).Font.Italic = True
wsDoc.Cells(ligneB, colDepart + 2).Font.Size = 16
wsDoc.Cells(ligneB, colDepart + 2).HorizontalAlignment = xlCenter
wsDoc.Cells(ligneB, colDepart + 2).VerticalAlignment = xlCenter
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Color = RGB(255, 0, 0)
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Bold = True
ElseIf debutMod <> "" And finMod <> "" Then
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Color = RGB(255, 0, 0)
wsDoc.Cells(ligneDoc, colDepart + 1).Font.Bold = True
Dim colModDebut As Long
Dim colModFin As Long
colModDebut = Int(CDbl(debutMod) * 96) + colDepart + 2
colModFin = Int(CDbl(finMod) * 96) + colDepart + 0
Dim shpTrait As Shape
Dim xDebut As Double
Dim xFin As Double
Dim yTrait As Double
xDebut = wsDoc.Cells(ligneB, colModDebut).Left
xFin = wsDoc.Cells(ligneB, colModFin).Left
yTrait = wsDoc.Cells(ligneB, colModDebut).Top + 35
Set shpTrait = wsDoc.Shapes.AddConnector(msoConnectorStraight, xDebut, yTrait, xFin, yTrait)
shpTrait.Line.ForeColor.RGB = RGB(255, 0, 0)
shpTrait.Line.Weight = 4
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colModDebut + 1), CDbl(debutMod), RGB(255, 0, 0), True
AjouterVignette wsDoc, wsDoc.Cells(ligneB, colModFin - DECALAGE_FIN), CDbl(finMod), RGB(255, 0, 0), True
End If
End If
With wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart + 1), wsDoc.Cells(ligneDoc + 2, colDepart + 1)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDoc, colDepart + 2), wsDoc.Cells(ligneDoc + 2, colDepart + 2)).Borders(xlEdgeLeft)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
wsDoc.Cells(ligneDoc, colDepart + 1).Borders(xlEdgeRight).LineStyle = xlContinuous
wsDoc.Cells(ligneDoc, colDepart + 1).Borders(xlEdgeRight).Weight = xlMedium
wsDoc.Cells(ligneDoc, colDepart + 1).Borders(xlEdgeRight).Color = RGB(0, 0, 0)
wsDoc.Cells(ligneDoc + 1, colDepart + 1).Borders(xlEdgeRight).LineStyle = xlContinuous
wsDoc.Cells(ligneDoc + 1, colDepart + 1).Borders(xlEdgeRight).Weight = xlMedium
wsDoc.Cells(ligneDoc + 1, colDepart + 1).Borders(xlEdgeRight).Color = RGB(0, 0, 0)
wsDoc.Cells(ligneDoc + 2, colDepart + 1).Borders(xlEdgeRight).LineStyle = xlContinuous
wsDoc.Cells(ligneDoc + 2, colDepart + 1).Borders(xlEdgeRight).Weight = xlMedium
wsDoc.Cells(ligneDoc + 2, colDepart + 1).Borders(xlEdgeRight).Color = RGB(0, 0, 0)
ligneDoc = ligneDoc + 3
End If
ligneSource = ligneSource + 1
Loop
Dim derniereLigne As Long
derniereLigne = ligneDoc - 1
' Bordures verticales complètes
With wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart), wsDoc.Cells(derniereLigne, colDepart)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
With wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart + 1), wsDoc.Cells(derniereLigne, colDepart + 1)).Borders(xlEdgeRight)
.LineStyle = xlContinuous: .Weight = xlMedium: .Color = RGB(0, 0, 0)
End With
' Bordures extérieures
With wsDoc.Range(wsDoc.Cells(ligneDepart, colDepart), wsDoc.Cells(derniereLigne, colDepart + COL_FIN))
.Borders(xlEdgeBottom).LineStyle = xlContinuous: .Borders(xlEdgeBottom).Weight = xlMedium: .Borders(xlEdgeBottom).Color = RGB(0, 0, 0)
.Borders(xlEdgeLeft).LineStyle = xlContinuous: .Borders(xlEdgeLeft).Weight = xlMedium: .Borders(xlEdgeLeft).Color = RGB(0, 0, 0)
.Borders(xlEdgeRight).LineStyle = xlContinuous: .Borders(xlEdgeRight).Weight = xlMedium: .Borders(xlEdgeRight).Color = RGB(0, 0, 0)
End With
' Traits gris verticaux
Dim hGris As Long
For hGris = 1 To 23
Dim colGris As Long
colGris = (hGris * 4) + colDepart + 2
With wsDoc.Range(wsDoc.Cells(ligneDepart + 5, colGris), wsDoc.Cells(derniereLigne, colGris)).Borders(xlEdgeLeft)
.LineStyle = xlContinuous: .Weight = xlHairline: .Color = RGB(200, 200, 200)
End With
Next hGris