Fonction VBA : IsMissing
La fonction VBA IsMissing renvoie False si l'argument optionnel a été renseigné ou True si ce n'est pas le cas.
Utilisation :
IsMissing(variable)
Exemple d'utilisation
Utilisation de la fonction IsMissing pour vérifier si l'argument optionnel nom a été renseigné ou non (et éviter dans ce cas d'afficher le nom dans la boîte de dialogue s'il n'a pas été renseigné) :
Sub afficherInfos(prenom, Optional nom)
If IsMissing(nom) Then
MsgBox "Je m'appelle " & prenom
Else
MsgBox "Je m'appelle " & prenom & " " & nom
End If
End Sub
Sub exemple()
'Renvoie : Je m'appelle John
afficherInfos "John"
'Renvoie : Je m'appelle John Smith
afficherInfos "John", "Smith"
End Sub