Saviez vous qu’il est possible de créer son propre type de variable en VBA? Prenons par exemple un cas ou on voudrait stocker les informations d’un participant à un marathon. On va se créer un type de variable qui sera Participant. On doit définir ce type dans un module et non dans une procédure.
Type Marathonien
Nom as String
Prenom as String
DateNaissance as Date
Catégorie as String
Cardiaque as Boolean
End Type
Ensuite on declare une variable avec le type qu’on vient de créer
Dim Participant as Marathonien
Pour attribuer ensuite des valeurs à Participant, on procède de la façon suivant
Participant.Nom = « McArthur »
Participant.Prenom = « Joseph »
Participant.DateNaissace = 1960-01-01
Participant.Catégorie = « 60 et + »
Participant.Cardiaque = True