Sub AppelMacro_Clic()
     'Macros associé au bouton AppelMacro
  
     Dim Choix$
     Choix = ""
     On Error Resume Next
     Choix = ShFiches.Shapes(Application.Caller).DrawingObject.Caption
     On Error GoTo 0
     Select Case Choix
        
          Case "", "En attente ..."
               Exit Sub
        
          Case "Générer un PDF de la fiche " & ShFiches.[N°]
               PdfFiche
            
          Case "Enregistrer la nouvelle Fiche"
               NouvelleFiche
        
          Case "Enregistrer les modifications de la fiche " & ShFiches.[N°]
               ModifFiche
            
          Case Else
               MsgBox Choix
  
     End Select
End Sub
Function N°Ligne(Wsh As Worksheet, TbdD, NumFiche As Range) As Long
     'Renvoie le N° de ligne dans le tableau TBdD de la fiche en cours
    
     N°Ligne = 0
     On Error Resume Next
     'Recherche du N° de ligne de la fiche "N°" dans 1ère colonne de la base
     N°Ligne = WorksheetFunction.Match(Wsh.[N°], WorksheetFunction.Index(TbdD, 0, 1), 0)
     On Error GoTo 0
  
End Function
Sub Afficher_Fiche()
     'Affiche la fiche "N°"
  
     Dim Wsh As Worksheet, TbdD, Ligne As Long
     Set Wsh = ShFiches
     'Tableau des données de la BdD
     TbdD = Wsh.[TBDD19]
     'Recherche du N° de ligne de la fiche en cours
     Ligne = N°Ligne(Wsh, TbdD, Wsh.[N°])
     If Ligne < 1 Then MsgBox "Veuillez renseigner un N° de Fiche valide": Exit Sub
  
     RemplirFiche Wsh, TbdD, Ligne
  
End Sub
Sub RemplirFiche(Wsh As Worksheet, TbdD, Ligne As Long)
     'Remplit la fiche avec les éléments de la ligne "Ligne" de la BdD
  
     Application.EnableEvents = False
     With Wsh
          .[DateFiche] = TbdD(Ligne, 3)
          .[NomPrénom] = TbdD(Ligne, 4)
          .[Zone] = TbdD(Ligne, 2)
        
          .[EPI_1 Obs] = TbdD(Ligne, 5)
          .[EPI_2 Obs] = TbdD(Ligne, 6)
          .[EPI_3 Obs] = TbdD(Ligne, 7)
          .[EPI_4 Obs] = TbdD(Ligne, 8)
        
          .[Gen_1 Obs] = TbdD(Ligne, 9)
          .[Gen_2 Obs] = TbdD(Ligne, 10)
          .[Gen_3 Obs] = TbdD(Ligne, 11)
          .[Gen_4 Obs] = TbdD(Ligne, 12)
          .[Gen_5 Obs] = TbdD(Ligne, 13)
          .[Gen_6 Obs] = TbdD(Ligne, 14)
          .[Gen_7 Obs] = TbdD(Ligne, 15)
        
          .[PI_1 Obs] = TbdD(Ligne, 16)
          .[PI_2 Obs] = TbdD(Ligne, 17)
          .[PI_3 Obs] = TbdD(Ligne, 18)
          .[PI_4 Obs] = TbdD(Ligne, 19)
          .[PI_5 Obs] = TbdD(Ligne, 20)
          .[PI_6 Obs] = TbdD(Ligne, 21)
          .[PI_7 Obs] = TbdD(Ligne, 22)
      
          .[A_Rmq] = TbdD(Ligne, 27)
          .[Spé_1] = TbdD(Ligne, 23)
          .[Spé_2] = TbdD(Ligne, 24)
          .[Spé_3] = TbdD(Ligne, 25)
          .[Spé_4] = TbdD(Ligne, 26)
     End With
     Application.EnableEvents = True
  
End Sub
Sub ViderFiche(Wsh As Worksheet)
     'Vider les champs de la fiche à l'exception du N°
  
     Application.EnableEvents = False
     With Wsh
          .[DateFiche].MergeArea.ClearContents
          .[NomPrénom].MergeArea.ClearContents
          .[Zone].MergeArea.ClearContents
        
          .[EPI_1 Obs].ClearContents
          .[EPI_2 Obs].ClearContents
          .[EPI_3 Obs].ClearContents
          .[EPI_4 Obs].ClearContents
        
          .[Gen_1 Obs].ClearContents
          .[Gen_2 Obs].ClearContents
          .[Gen_3 Obs].ClearContents
          .[Gen_4 Obs].ClearContents
          .[Gen_5 Obs].ClearContents
          .[Gen_6 Obs].ClearContents
          .[Gen_7 Obs].ClearContents
        
          .[PI_1 Obs].ClearContents
          .[PI_2 Obs].ClearContents
          .[PI_3 Obs].ClearContents
          .[PI_4 Obs].ClearContents
          .[PI_5 Obs].ClearContents
          .[PI_6 Obs].ClearContents
          .[PI_7 Obs].ClearContents
      
          .[A_Rmq].MergeArea.ClearContents
          .[Spé_1].MergeArea.ClearContents
          .[Spé_2].MergeArea.ClearContents
          .[Spé_3].MergeArea.ClearContents
          .[Spé_4].MergeArea.ClearContents
     End With
     Application.EnableEvents = True
  
End Sub
Sub NouvelleFiche()
     'Ajouter une fiche à la BdD
     Dim Wsh As Worksheet, Ligne As Long
     Set Wsh = ShFiches
     With Wsh
          N° = WorksheetFunction.Max(WorksheetFunction.Index(.[TBDD19], 0, 1)) + 1 'Nouveau N° de Fiche
        
          Application.EnableEvents = False
          .[N°] = N°
          If N° > 1 Then .ListObjects("TBDD19").ListRows.Add 'Ajouter une ligne si la BdD n'est pas vide
          Application.EnableEvents = True
        
          Ligne = .[TBDD19].Rows.Count
          EnregistrerFiche Wsh, .[TBDD19], Ligne
     End With
  
End Sub
Sub ModifFiche()
     Dim Wsh As Worksheet, TbdD, Ligne As Long
     Set Wsh = ShFiches
     TbdD = Wsh.[TBDD19]
     Ligne = N°Ligne(Wsh, TbdD, Wsh.[N°])
     EnregistrerFiche Wsh, Wsh.[TBDD19], Ligne
  
End Sub
Sub EnregistrerFiche(Wsh As Worksheet, LORg As Range, N°Ligne As Long)
     'Enregistrer la fiche courante dans la BdD (au N° de Ligne indiqué)
  
     ReDim TbRés(1 To 1, 1 To LORg.Columns.Count) 'Tableau 1 ligne pour stocker les infos puis les écrire à la ligne N°Ligne
     With Wsh
          TbRés(1, 1) = .[N°]
          TbRés(1, 3) = .[DateFiche]
          TbRés(1, 4) = .[NomPrénom]
          TbRés(1, 2) = .[Zone]
        
          TbRés(1, 5) = .[EPI_1 Obs].Cells(1)
          TbRés(1, 6) = .[EPI_2 Obs].Cells(1)
          TbRés(1, 7) = .[EPI_3 Obs].Cells(1)
          TbRés(1, 8) = .[EPI_4 Obs].Cells(1)
        
          TbRés(1, 9) = .[Gen_1 Obs].Cells(1)
          TbRés(1, 10) = .[Gen_2 Obs].Cells(1)
          TbRés(1, 11) = .[Gen_3 Obs].Cells(1)
          TbRés(1, 12) = .[Gen_4 Obs].Cells(1)
          TbRés(1, 13) = .[Gen_5 Obs].Cells(1)
          TbRés(1, 14) = .[Gen_6 Obs].Cells(1)
          TbRés(1, 15) = .[Gen_7 Obs].Cells(1)
        
          TbRés(1, 16) = .[PI_1 Obs].Cells(1)
          TbRés(1, 17) = .[PI_2 Obs].Cells(1)
          TbRés(1, 18) = .[PI_3 Obs].Cells(1)
          TbRés(1, 19) = .[PI_4 Obs].Cells(1)
          TbRés(1, 20) = .[PI_5 Obs].Cells(1)
          TbRés(1, 21) = .[PI_6 Obs].Cells(1)
          TbRés(1, 22) = .[PI_7 Obs].Cells(1)
      
          TbRés(1, 27) = .[A_Rmq]
          TbRés(1, 23) = .[Spé_1]
          TbRés(1, 24) = .[Spé_2]
          TbRés(1, 25) = .[Spé_3]
          TbRés(1, 26) = .[Spé_4]
     End With
     Application.EnableEvents = False
     LORg.Rows(N°Ligne).Value = TbRés      'Ecrire les infos dans la BdD à la ligne N°Ligne
     Application.EnableEvents = True
End Sub
Sub PdfFiche()
     'Génère le pdf de la fiche en cours
     Dim NomFich$, ZImp$
     With ShFiches
          ZImp = .[Fiche].Address
          With .PageSetup
               'Zone d'impression de la fiche d inspection
               .PrintArea = ZImp
               .Zoom = False
               'Ajustement à 1 page
               .FitToPagesWide = 1
               .FitToPagesTall = 1
               'Centrage
               .CenterHorizontally = True
               .CenterVertically = False
               .Orientation = xlPortrait                            'Portrait
               'Réglage des marges
               .LeftMargin = Application.CentimetersToPoints(0.5)   'Marge gauche 5mm
               .RightMargin = Application.CentimetersToPoints(0.5)  'Marge droite 5mm
               .TopMargin = Application.CentimetersToPoints(0.5)    'Marge haut de page 5mm
               .BottomMargin = Application.CentimetersToPoints(0.5) 'Marge bas de page 5mm
          End With
          NomFich = ThisWorkbook.Path & "\Fiche d'inspection N°" & .[N°] & ".pdf"   'Nom du fichier produit
          MsgBox "Génération du fichier pdf" & Chr(10) & NomFich
          'Génération du fichier pdf
          .[Fiche].ExportAsFixedFormat Type:=xlTypePDF, _
                                      Filename:=NomFich, _
                                      Quality:=xlQualityStandard, _
                                      IncludeDocProperties:=False, _
                                      IgnorePrintAreas:=False, _
                                      OpenAfterPublish:=True
                                    
          MsgBox "Penser à imprimer le fichier générer"
     End With
End Sub