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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
|
Public Sub Extraction_CR_signed()
Dim olApp As Outlook.Application
Dim olSpace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olInbox As Outlook.MAPIFolder
Dim olmail As Outlook.MailItem
Dim pceJointe As Outlook.Attachment
Dim fich As Object
Dim y As Integer, x As Integer
Dim NomDossier As String
Dim myDestFolder As Outlook.MAPIFolder
Dim Type_Fichier As String
Dim estouvert As Boolean
Dim continuer As String
Dim Nom_Presta As String
'Dim Periode As String
Dim DotPosition As Byte
Dim SemPosition As Byte
Dim Longueur_NumSemaine As Byte
Dim Longueur_Nom_Presta As Integer
Dim Num_Semaine As Integer
Dim Num_Mois As Integer
Dim Site As String
Dim Fact_HNO_FullFileName As String
Dim Effectifs_FullFileName As String
Dim annee As Integer
Dim Num_TP As Long
Dim Row_Ast As Integer
Dim Col_Ast As Integer
Dim Alpha_ColMois As String
Dim Cell As Range
Dim Row As Integer
Dim SSII As String
Dim TypeHNO As Integer
'---- variables pour le choix ds 1 liste déroulante -----------------
Dim i As Integer
Dim TopPos As Integer
Dim PrintDlg As DialogSheet
Dim cb As OptionButton
'Dim Choix1, Choix2
Dim Choix1 As Variant
'Dim fichier As Object
Dim ArrChoix As Variant
debut:
Application.Calculation = xlManual ' bloque le calcul automatique.
Set olApp = New Outlook.Application
Set olSpace = olApp.GetNamespace("MAPI")
Set olInbox = olSpace.GetDefaultFolder(olFolderInbox)
'dans cet exemple, le dossier "CRs signed" est supposé etre un sous repertoire de la boite de réception
NomDossier = "CRs signed"
Set olFolder = olInbox.Folders(NomDossier)
'récupération des infos
Fact_HNO_FullFileName = ThisWorkbook.Name
Effectifs_FullFileName = "TdB_effectifs.xlsx"
'test si le(s) classeur(s) sont ouverts
estouvert = False
For Each fich In Workbooks
If fich.Name = Effectifs_FullFileName Then estouvert = True
Next
If estouvert = False Then
If FileDateTime("C:\fichiersxls\" & Effectifs_FullFileName) < Date Then
MsgBox ("les fichiers shpt n'ont pas été copiés en local ! :-(")
'ChDir "C:\fichiersxls"
Exit Sub
Else
Workbooks.Open Filename:="C:\fichiersxls\" & Effectifs_FullFileName, UpdateLinks:=0
End If
End If
'On regarde dans tous les mails du dossier
For Each olmail In olFolder.Items
'Debug.Print olmail.SenderEmailAddress
On Error GoTo 0
'S'il y a un fichier joint au mail
'If olmail.SenderEmailAddress = Expediteur And _
Not olmail.Attachments.Count = 0 Then
If olmail.Attachments.Count > 0 Then
x = 0 'nb de pièces jointes traitées pour le mail considéré
'Debug.Print CDate(Format(olmail.ReceivedTime, "dd/mm/yyyy hh:nn"))
'Pour toutes les pièces jointes du mail sélectionné (de 1 jusqu'à la dernière)
For y = 1 To olmail.Attachments.Count
'si l'extension de la piece jointe = "pdf"
If Right(olmail.Attachments(y), 3) = "pdf" Or Right(olmail.Attachments(y), 3) = "doc" Then
'On récupère la pièce jointe n°y
Set pceJointe = olmail.Attachments(y)
Debug.Print pceJointe
x = x + 1 'on incémente le nb de pieces jointes traitées
'vérif si nom fichier au format Astr
Longueur_Nom_Presta = InStr(1, pceJointe, "_w") - 2 'position de _w ds le nom du fichier
If Longueur_Nom_Presta < 0 Then
Longueur_Nom_Presta = InStr(1, pceJointe, "-w") - 2 'position de -w ds le nom du fichier
End If
If Longueur_Nom_Presta > 0 Then '--> CR Astr
Nom_Presta = Trim(Mid(pceJointe, 2, Longueur_Nom_Presta))
Nom_Presta = Trim(Mid(UCase(Nom_Presta), 1, 1)) & Trim(Mid(LCase(Nom_Presta), 2, Longueur_Nom_Presta - 1))
'si c'est JCLegatte_... alors on enlève encore 1 caractère
If Nom_Presta = "Clegatte" Then Nom_Presta = "Legatte"
Debug.Print Nom_Presta
'test sur effectifs
Windows(Effectifs_FullFileName).Activate
'supp filtres éventuels
Range("A1").Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
Selection.AutoFilter
'Si une erreur survient, on va à la ligne "errorPrestaNameHandler" et on arrête la macro
'On Error GoTo errorPrestaNameHandler
On Error Resume Next
If Nom_Presta <> "beer" Then
'on teste la présence du nom exactement identique dans l'onglet "effectifs" :
'With Workbooks(Effectifs_FullFileName).Sheets(1)
' .Range("a1:a500").Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'End With
Columns("A:A").Select
Selection.Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
End If
On Error GoTo 0
Windows(Fact_HNO_FullFileName).Activate
SemPosition = InStr(1, pceJointe, "W") + 1 'position du début du n° de semaine
'Periode = "W"
'on cherche le 1er K numérique
While Not IsNumeric(Mid(pceJointe, SemPosition, 1))
'Periode = "WE"
SemPosition = SemPosition + 1 'position du début du n° de semaine
Wend
DotPosition = InStr(1, pceJointe, ".") 'position du .
'on regarde le nb de caract du n° de semaine
If DotPosition - SemPosition >= 2 Then
Num_Semaine = Mid(pceJointe, SemPosition, 2) 'n° de semaine
Else
Num_Semaine = Mid(pceJointe, SemPosition, 1) 'n° de semaine
End If
Debug.Print Num_Semaine
'MAJ xls HNO onglet export_RDU avec date du jour
Windows(Fact_HNO_FullFileName).Activate
Sheets("export_RDU").Select
'supp filtres
Range("A2").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter
'filtre sur presta/semaine
'On Error GoTo fin_boucle
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=14, Criteria1:=Nom_Presta
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=60, Criteria1:=Num_Semaine
'rech derniere ligne
Row_Ast = Sheets("export_RDU").Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
'si tableau vide, mssg d'erreur
If Row_Ast = 2 Then
MsgBox ("Aucune intervention pour " & Nom_Presta & " W" & Num_Semaine & ", corriger et relancer.")
Exit Sub
End If
'MAJ colonne "reçu SSII" avec date du jour
Rows("2").Select
Selection.Find(What:="reçu SSII", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Range(Alpha_ColMois & Row).Select
Range(Alpha_ColMois & Row).Value = CDate(Format(olmail.ReceivedTime, "dd/mm/yyyy"))
Next
'récup site
Rows("2").Select
Selection.Find(What:="site", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
Site = Range(Alpha_ColMois & Row).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
'récup ssii porteuse
Rows("2").Select
Selection.Find(What:="SSII_porteuse_Int", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
SSII = Range(Alpha_ColMois & Row).Value
'récup n° mois
Rows("2").Select
Selection.Find(What:="mois_Int", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
Num_Mois = Format(Range(Alpha_ColMois & Row).Value, "00")
If Num_Semaine > 50 And Num_Mois = 1 Then Num_Mois = 12
'récup année
'Rows("2").Select
'Selection.Find(What:="date et heure", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'Col_Ast = ActiveCell.Column
'Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
'For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
' Row = Cell.Row
'Next
'Range(Alpha_ColMois & Row).Select
'annee = Year(Range(Alpha_ColMois & Row).Value)
annee = 2016
On Error GoTo 0
'supp filtres
'ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=60
'ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=14
'ENR pièce jointe ss shpt
pceJointe.SaveAsFile "Y:\test\CRA astreintes et TPs\Astreintes\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & SSII & "-" & Nom_Presta & "-w" & Num_Semaine & "-signed.pdf"
'del fichier équivalent ss "1-envoyé SSII"
On Error Resume Next
Kill "Y:\test\CRA astreintes et TPs\Astreintes\1-envoyé SSII\" & Site & "\" & Num_Mois & "\" & pceJointe
Else
'verif si nom fichier au format TP
'If Not IsNumeric(Trim(Mid(pceJointe, 1, 1))) Then 'si 1er K <> numerique
Longueur_Nom_Presta = InStr(1, pceJointe, "_") - 1 'position de "_" ds le nom du fichier
If Longueur_Nom_Presta < 0 Then
Longueur_Nom_Presta = InStr(1, pceJointe, "-") - 1 'position de - ds le nom du fichier
End If
If Longueur_Nom_Presta > 0 Then 'check si conforme CR TP
Nom_Presta = Trim(Mid(pceJointe, 1, Longueur_Nom_Presta))
'traitt des erreurs
'si clic sur Annuler (vide)
If Nom_Presta = "" Then Exit Sub
Debug.Print Nom_Presta
'si nom_presta n'est pas ds les effectifs
Windows(Effectifs_FullFileName).Activate
'supp filtres éventuels
Range("A1").Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
Selection.AutoFilter
'Si une erreur survient, on va à la ligne "errorPrestaNameHandler" et on arrête la macro
'On Error GoTo errorPrestaNameHandler
On Error GoTo pdfNonConforme
If Nom_Presta <> "beer" Then
'on teste la présence du nom exactement identique dans l'onglet "effectifs" :
'With Workbooks(Effectifs_FullFileName).Sheets(1)
'.Range("a1:a500").Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'End With
Columns("A:A").Select
Selection.Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
End If
On Error GoTo 0
Windows(Fact_HNO_FullFileName).Activate
'Longueur_Nom_Presta = Len(Nom_Presta)
Num_TP = Mid(pceJointe, Len(Nom_Presta) + 2, InStr(1, pceJointe, "-") - Len(Nom_Presta) - 2)
'traitt des erreurs
If Not IsNumeric(Num_TP) Then GoTo MsgErr
'Debug.Print "num tp :" & Num_TP
'xls HNO, onglet TPs
Windows(Fact_HNO_FullFileName).Activate
Sheets("Planning TPs").Select
'supp filtres
Range("A2").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter
'récup année, mois, SSII
Columns("A:A").Select
Selection.Find(What:=Num_TP & "_" & Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
annee = Year(ActiveCell.Offset(0, 2).Value)
Num_Mois = Month(ActiveCell.Offset(0, 2).Value)
Site = ActiveCell.Offset(0, 29).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
SSII = ActiveCell.Offset(0, 20).Value
'MAJ xls HNO onglet TP avec date du jour
ActiveCell.Offset(0, 35).Value = CDate(Format(olmail.ReceivedTime, "dd/mm/yyyy"))
'Debug.Print SSII
'ENR pièce jointe ss shpt
'Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\2016\Bagnolet\12
On Error Resume Next
pceJointe.SaveAsFile "Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe
Debug.Print Error
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 & "''")
On Error GoTo 0
'del fichier équivalent ss "1-envoyé SSII"
On Error Resume Next
pceJointe = Nom_Presta & "_" & Num_TP & "-*.pdf"
'Debug.Print pceJointe
Kill "Y:\test\CRA astreintes et TPs\TP\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
'End If
Else 'nom CR Astr et TP non conforme
SaisiePresta:
pdfNonConforme:
'save sur C:/
pceJointe.SaveAsFile "C:\Users\obwe6245\Documents\work-tmp\FTV\" & pceJointe
'ouverture pdf
'ThisWorkbook.FollowHyperlink "C:\leFichier.pdf"
ThisWorkbook.FollowHyperlink Address:="C:\Users\obwe6245\Documents\work-tmp\FTV\" & pceJointe
'on demande les infos à traiter
Nom_Presta = InputBox("Nom du prestataire ?", Admin)
'traitt des erreurs
'si clic sur Annuler (vide)
If Nom_Presta = "" Then GoTo errorPrestaNameHandler
'si nom_presta n'est pas ds les effectifs
Windows(Effectifs_FullFileName).Activate
'supp filtres éventuels
Range("A1").Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
Selection.AutoFilter
'Si une erreur survient, on va à la ligne "errorPrestaNameHandler" et on arrête la macro
On Error GoTo errorPrestaNameHandler
'On Error Resume Next
If Nom_Presta <> "beer" Then
'on teste la présence du nom exactement identique dans l'onglet "effectifs" :
'With Workbooks(Effectifs_FullFileName).Sheets(1)
'.Range("a1:a500").Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'End With
Columns("A:A").Select
Debug.Print Nom_Presta
Selection.Find(What:=Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
End If
On Error GoTo 0
Windows(Fact_HNO_FullFileName).Activate
'----------------------------------------------------------
'----------------------------------------------------------
' Permet l'affichage d'une boîte de dialogue
' pour choisir entre plus de deux options
Application.ScreenUpdating = False
' Ajoute une feuille de dialogue temporaire
Set PrintDlg = ActiveWorkbook.DialogSheets.Add
' Ajoute les boutons d'option
ArrChoix = Array("", "Astreinte", "Perm Stat", "TP")
TopPos = 100
For i = 1 To 3
PrintDlg.OptionButtons.Add 78, TopPos, 150, 16.5
PrintDlg.OptionButtons(i).Text = ArrChoix(i)
TopPos = TopPos + 13
Next i
' Positionne les boutons OK et Annuler
PrintDlg.Buttons.Top = 120
'ajout d'un texte dans la boite de dialogue
ActiveSheet.Labels.Add(80, 50, 160, 35).Select
Selection.Characters.Text = "Option pour le type de HNO :"
' Dimensionne la hauteur, la largeur et le titre de la bte de dialogue
With PrintDlg.DialogFrame
'.Height = Application.Max(68, PrintDlg.DialogFrame.Top + TopPos - 34)
'.Height = 130
'.Width = 230
.Caption = "Choisissez une option"
End With
' Change l'ordre de tabulation des boutons OK et Annuler
' afin de donner le focus au premier bouton d'option
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront
PrintDlg.Show
' récupération du choix effectué
For i = 1 To 3
If PrintDlg.OptionButtons(i).Value = xlOn Then
Choix1 = PrintDlg.OptionButtons(i).Text
End If
Next
If Choix1 = "" Then
MsgBox "Aucun choix n'a été fait"
GoTo MsgErr
End If
' Supprime la feuille de dialogue temporaire (sans message d'avertissement)
Application.DisplayAlerts = False
PrintDlg.Delete
Application.DisplayAlerts = True
'--------------- fin procédure choix ds 1 liste déroulante -------------
'--------------- fin procédure choix ds 1 liste déroulante -------------
'--------------- fin procédure choix ds 1 liste déroulante -------------
TypeHNO = CInt(Choix1)
If TypeHNO = 3 Then
SaisieTP:
Num_TP = InputBox("No du TP ?", Admin)
'traitt des erreurs
If Not IsNumeric(Num_TP) Then GoTo MsgErr
Windows(Fact_HNO_FullFileName).Activate
Sheets("Planning TPs").Select
'supp filtres
Range("A2").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter
'récup année, mois, SSII
Columns("A:A").Select
Selection.Find(What:=Num_TP & "_" & Nom_Presta, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
annee = Year(ActiveCell.Offset(0, 2).Value)
Num_Mois = Month(ActiveCell.Offset(0, 2).Value)
Site = ActiveCell.Offset(0, 29).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
SSII = ActiveCell.Offset(0, 20).Value
'MAJ xls HNO onglet TP avec date du jour
ActiveCell.Offset(0, 35).Value = CDate(Format(olmail.ReceivedTime, "dd/mm/yyyy"))
'ENR pièce jointe ss shpt
Dim pceJointe_new As String
pceJointe_new = Nom_Presta & "_" & Num_TP & "-" & pceJointe
Debug.Print pceJointe_new
Debug.Print "Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe
pceJointe.SaveAsFile "Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe
Name "Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe As "Y:\test\CRA astreintes et TPs\TP\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & pceJointe_new
'del fichier équivalent ss "1-envoyé SSII"
On Error Resume Next
Kill "C:\Users\obwe6245\Documents\work-tmp\FTV\" & pceJointe
pceJointe = Nom_Presta & "_" & Num_TP & "*.pdf"
Kill "Y:\test\CRA astreintes et TPs\TP\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
Else
If TypeHNO = 1 Then 'si astreinte
Num_Semaine = InputBox("N° de la semaine ?", Admin)
'traitt des erreurs
If Not IsNumeric(Num_Semaine) Then GoTo MsgErr
Windows(Fact_HNO_FullFileName).Activate
Sheets("export_RDU").Select
'supp filtres
Range("A2").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter
'filtre sur presta/semaine
'On Error GoTo fin_boucle
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=14, Criteria1:=Nom_Presta
ActiveSheet.ListObjects("Tableau9").Range.AutoFilter Field:=60, Criteria1:=Num_Semaine
'rech derniere ligne
Row_Ast = Sheets("export_RDU").Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
'si tableau vide, mssg d'erreur
If Row_Ast = 2 Then
MsgBox ("Aucune intervention pour " & Nom_Presta & " W" & Num_Semaine & ", corriger et relancer.")
Exit Sub
End If
'MAJ colonne "reçu SSII" avec date du jour
Rows("2").Select
Selection.Find(What:="reçu SSII", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Range(Alpha_ColMois & Row).Select
Range(Alpha_ColMois & Row).Value = CDate(Format(olmail.ReceivedTime, "dd/mm/yyyy"))
Next
'récup site
Rows("2").Select
Selection.Find(What:="site", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
Site = Range(Alpha_ColMois & Row).Value
If LCase(Site) = "mougins" Then Site = "Sophia-Antipolis"
'récup ssii porteuse
Rows("2").Select
Selection.Find(What:="SSII_porteuse_Int", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
SSII = Range(Alpha_ColMois & Row).Value
'récup n° mois
Rows("2").Select
Selection.Find(What:="mois_Int", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
Num_Mois = Format(Range(Alpha_ColMois & Row).Value, "00")
If Num_Semaine > 50 And Num_Mois = 1 Then Num_Mois = 12
'récup 1ere lettre prénom
Dim FirstPrenom
Rows("2").Select
Selection.Find(What:="Prénom", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Col_Ast = ActiveCell.Column
Alpha_ColMois = Split(Columns(ActiveCell.Column).Address(columnabsolute:=False), ":")(1)
For Each Cell In Range(Alpha_ColMois & "3:" & Alpha_ColMois & Row_Ast).SpecialCells(xlCellTypeVisible).Rows
Row = Cell.Row
Next
Range(Alpha_ColMois & Row).Select
FirstPrenom = Mid(Range(Alpha_ColMois & Row).Value, 1, 1)
annee = 2016
On Error GoTo 0
'ENR pièce jointe ss shpt
pceJointe.SaveAsFile "Y:\test\CRA astreintes et TPs\Astreintes\2-revenu signé SSII\" & annee & "\" & Site & "\" & Num_Mois & "\" & SSII & "-" & Nom_Presta & "-w" & Num_Semaine & "-signed.pdf"
'del fichier équivalent ss "1-envoyé SSII"
On Error Resume Next
Kill "C:\Users\obwe6245\Documents\work-tmp\FTV\" & pceJointe
pceJointe = FirstPrenom & Nom_Presta & "-w" & Num_Semaine & "*.pdf"
Kill "Y:\test\CRA astreintes et TPs\Astreintes\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
Else 'PermStat
MsgBox ("traitt à faire ds la macro pour les PS... :-(")
End If 'fin si typeHNO=Astr
End If 'fin si typeHNO=TP
End If 'fin check si CR TP
End If 'fin si CR ASTr
Set pceJointe = Nothing
fin_boucle:
End If 'fin si extension = "pdf"
'On passe à la pièce jointe suivante
Next y
'si aucune pièce jointe traitée, message
If x = 0 Then
MsgBox ("PB : aucune pièce jointe traitée !!")
End If
End If
'marquer le mail comme étant lu
olmail.unread = False
'Déplacement du mail dans un autre dossier du .pst
Set myDestFolder = olSpace.Folders("Dossiers personnels Hebex")
Set myDestFolder = myDestFolder.Folders("GFAT Team")
Set myDestFolder = myDestFolder.Folders("z-HNO, déplacts, etc")
If Nom_Presta = "legatte" Or Nom_Presta = "thebaud" Or Nom_Presta = "zimmer" Then
Set myDestFolder = myDestFolder.Folders("*akka")
Set myDestFolder = myDestFolder.Folders(CStr(annee))
Set myDestFolder = myDestFolder.Folders(Nom_Presta)
GoTo MoveMail
End If
Select Case SSII
Case Is = "Aepsilon", "BeMore", "Blue Soft", "BlueSoft", "Squad"
Set myDestFolder = myDestFolder.Folders("*akka")
Set myDestFolder = myDestFolder.Folders(CStr(annee))
Set myDestFolder = myDestFolder.Folders(SSII)
Case Is = "acg", "CRI", "Komposite", "Look For", "Look-For", "Orness"
Set myDestFolder = myDestFolder.Folders("*aptech")
Set myDestFolder = myDestFolder.Folders(CStr(annee))
Set myDestFolder = myDestFolder.Folders(SSII)
Case Is = "OSIATIS"
Set myDestFolder = myDestFolder.Folders("Osiatis (Econocom-ESR)")
Set myDestFolder = myDestFolder.Folders(CStr(annee))
Case Else
'Set myDestFolder = olSpace.Folders("Dossiers personnels Hebex")
'Set myDestFolder = myDestFolder.Folders("GFAT Team")
'Set myDestFolder = myDestFolder.Folders("z-HNO, déplacts, etc")
Set myDestFolder = myDestFolder.Folders(SSII)
Set myDestFolder = myDestFolder.Folders(CStr(annee))
End Select
MoveMail:
olmail.Move myDestFolder
'On passe au mail suivant
Next olmail
' met en place le calcul automatique
'Application.Calculation = xlAutomatic
errorPrestaNameHandler:
'MsgBox ("Le nom du prestataire " & Nom_Presta & " n'est pas correct.")
continuer = MsgBox("Le nom du prestataire " & Nom_Presta & " n'est pas correct." & vbCrLf & "voulez-vs continuer ?", vbYesNo, Admin)
If continuer = vbNo Then Exit Sub
GoTo SaisiePresta
MsgErr:
'MsgBox ("Le No du TP " & Num_TP & " n'est pas correct.")
continuer = MsgBox("Le No du TP " & Num_TP & " n'est pas correct." & vbCrLf & "voulez-vs reprendre ?", vbYesNo, Admin)
If continuer = vbNo Then Exit Sub
GoTo SaisieTP
End Sub |
Partager