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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| Sub Trait_pdf_HNO_recu(Numero As Long, Nom_Presta As String, pceJointe As String, Fact_HNO_FullFileName As String, olmail_ReceivedTime As Date, trouve As Boolean)
'Public Function Trait_pdf_HNO_recu(Numero As Long, Nom_Presta As String, pceJointe As String, Fact_HNO_FullFileName As String, olmail_ReceivedTime As Date, trouve As Boolean) As String
Dim continuer As String
Dim reponse As String
Dim pceJointe_new As String
Dim FirstPrenom As String
Dim annee As Integer
Dim Num_Mois As Variant
Dim Site As String
Dim SSII As String
Dim Row_WB As Integer
Dim Col_WB As Integer
Dim Col_Presta As Integer
Dim Row As Integer
Dim HNO As String
Dim cell As Range
'xls HNO
Windows(Fact_HNO_FullFileName).Activate
'select onglet
If Numero > 55 Then
Sheets("Planning TPs").Select
HNO = "TP"
Else
Sheets("export_RDU").Select
HNO = "Astreintes"
End If
'supp filtres
Range("A2").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter
If Numero > 55 Then 'TP
'récup année, mois, SSII
Columns("A:A").Select
Selection.Find(What:=Numero & "_" & Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'MAJ xls HNO onglet TP avec date du jour
Col_WB = Range("recuSSIITP").Column
If Cells(ActiveCell.Row, Col_WB).Value = "" Then
Cells(ActiveCell.Row, Col_WB).Value = olmail_ReceivedTime
Else
continuer = MsgBox("fichier a priori déjà reçu le " & Cells(ActiveCell.Row, Col_WB).Value & " : continuer ?", vbYesNo)
If continuer = vbNo Then GoTo fermeture
End If
Col_WB = Range("dateTP").Column
annee = Year(Cells(ActiveCell.Row, Col_WB).Value)
If Month(Cells(ActiveCell.Row, Col_WB).Value) > 9 Then
Num_Mois = CStr(Month(Cells(ActiveCell.Row, Col_WB).Value))
Else
Num_Mois = "0" & CStr(Month(Cells(ActiveCell.Row, Col_WB).Value))
End If
If Numero > 50 And Numero < 55 And Num_Mois = "01" Then Num_Mois = "12"
Col_WB = Range("siteTP").Column
Site = Cells(ActiveCell.Row, Col_WB).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
Col_WB = Range("SSII_porteuse_TP").Column
SSII = Cells(ActiveCell.Row, Col_WB).Value
Else 'astreinte
'filtre sur presta/semaine
Col_Presta = Range("Nom").Column
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=Range("Nom").Column, Criteria1:=Nom_Presta
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=Range("semaineAST").Column, Criteria1:=Numero
'rech derniere ligne
Row_WB = Sheets("export_RDU").Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
'si tableau vide, mssg d'erreur
If Row_WB = 2 Then
MsgBox ("Aucune intervention trouvée pour " & Nom_Presta & " en W" & Numero & ", corriger et relancer.")
'ouvrir pdf + dder si on continue ou pas (ENR pdf sur shpt + del)
ThisWorkbook.FollowHyperlink Address:=pceJointe
reponse = MsgBox("ENR le pdf sous shpt (si ''non'', arrêt) ?", vbYesNo)
If reponse = vbYes Then
GoTo Enr_Del_PDF
Else
Exit Sub
End If
End If
'MAJ colonne "reçu SSII" avec date du jour si pas deja renseigné
Col_WB = Range("recuSSIIAstr").Column
For Each cell In Range(Cells(3, Col_WB), Cells(Row_WB, Col_WB)).SpecialCells(xlCellTypeVisible).Rows
Row = cell.Row
Cells(Row, Col_WB).Select
If Cells(Row, Col_WB).Value = "" Then
Cells(Row, Col_WB).Value = olmail_ReceivedTime
Else
continuer = MsgBox("fichier a priori déjà reçu le " & Cells(Row, Col_WB).Value & " : continuer ?", vbYesNo)
If continuer = vbNo Then GoTo fermeture
End If
Next
'récup site
Col_WB = Range("siteAstr").Column
For Each cell In Range(Cells(3, Col_WB), Cells(Row_WB, Col_WB)).SpecialCells(xlCellTypeVisible).Rows
Row = cell.Row
Next
Site = Cells(Row, Col_WB).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
'récup année
Col_WB = Range("date_et_heure").Column
annee = Year(Cells(ActiveCell.Row, Col_WB).Value)
'récup ssii porteuse
Col_WB = Range("SSII_porteuse_IntAstr").Column
SSII = Cells(Row, Col_WB).Value
'récup n° mois
Col_WB = Range("moisInterv").Column
If Cells(Row, Col_WB).Value > 9 Then
Num_Mois = CStr(Cells(Row, Col_WB).Value)
Else
Num_Mois = "0" & CStr(Cells(Row, Col_WB).Value)
End If
If Numero > 50 And Num_Mois = "01" Then Num_Mois = "12"
'supp filtres
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=Range("Nom").Column
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=Range("semaineAST").Column
'fin si TP/Astr (Numero > 55)
End If
Enr_Del_PDF:
'On Error GoTo 0
'ENR pièce jointe ss shpt sous un nv nom
If HNO = "TP" Then
pceJointe_new = SSII & "-" & Nom_Presta & "_" & Numero & "-signed.pdf"
Else
'supp filtres
Workbooks(Fact_HNO_FullFileName).Activate
Sheets("export_RDU").Activate --> là ca plante puisque la feuille active est celle de mon PERSONAL.XLSB
Debug.Print ActiveSheet.Name
With Workbooks(Fact_HNO_FullFileName).Sheets("export_RDU")
If .AutoFilterMode Then
.Cells.AutoFilter
End If
End With
'on ne met que le filtre sur le presta pour pouvoir avoir au moins 1 ligne avec le prénom
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=Col_Presta, Criteria1:=Nom_Presta
'rech derniere ligne
Row_WB = Sheets("export_RDU").Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
'si tableau vide, mssg d'erreur
If Row_WB = 2 Then
MsgBox ("Aucune intervention trouvée pour " & Nom_Presta & " en W" & Numero & " --> sortie / ENR manuellement.")
Exit Sub
End If
'récup 1ere lettre prénom
Col_WB = Range("PrenomAstr").Column
FirstPrenom = Mid(Cells(Row_WB, Col_WB).Value, 1, 1)
pceJointe_new = SSII & "-" & FirstPrenom & Nom_Presta & "-w" & Numero & ".pdf"
End If
FileCopy pceJointe, "Y:\test\CRA astreintes et TPs\" & HNO & "\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe_new
If Error = "Impossible d'enregistrer la pièce jointe." Then MsgBox ("Impossible d'enregistrer la pièce jointe --> copier le fichier à la main dans ''2-revenu signé SSII/" & Site & "/" & Num_Mois & "''") '
fermeture:
pceJointe = "*" & Nom_Presta & "*.pdf"
Kill "Y:\test\" & LCase(pceJointe)
On Error Resume Next
Kill "Y:\test\CRA astreintes et TPs\" & HNO & "\1-envoyé SSII\" & Site & "\" & Num_Mois & "\" & pceJointe
If Error = "Fichier introuvable" Then MsgBox ("Fichier introuvable --> supp. le fichier à la main de ''1-envoyé SSII/" & Site & "/" & Num_Mois & "''")
On Error GoTo 0
'Trait_pdf_HNO_recu = CStr(SSII & "-" & annee)
End Sub |