Fonction VBA : MonthName

La fonction VBA MonthName renvoie le nom du mois en fonction du numéro du mois (de 1 à 12).

Utilisation :

MonthName(numéro)

ou

MonthName(numéro, abréviation)


Exemples d'utilisation

Utilisation de la fonction MonthName pour afficher le nom des 12 mois :

Sub exemple()
    
    MsgBox MonthName(1) 'Renvoie : janvier
    MsgBox MonthName(2) 'Renvoie : février
    MsgBox MonthName(3) 'Renvoie : mars
    MsgBox MonthName(4) 'Renvoie : avril
    MsgBox MonthName(5) 'Renvoie : mai
    MsgBox MonthName(6) 'Renvoie : juin
    MsgBox MonthName(7) 'Renvoie : juillet
    MsgBox MonthName(8) 'Renvoie : août
    MsgBox MonthName(9) 'Renvoie : septembre
    MsgBox MonthName(10) 'Renvoie : octobre
    MsgBox MonthName(11) 'Renvoie : novembre
    MsgBox MonthName(12) 'Renvoie : décembre
    
End Sub

La fonction MonthName peut également afficher la version abrégée du mois en entrant la valeur True en second argument :

Sub exemple()
    
    MsgBox MonthName(1, True) 'Renvoie : janv
    MsgBox MonthName(2, True) 'Renvoie : févr
    MsgBox MonthName(3, True) 'Renvoie : mars
    MsgBox MonthName(4, True) 'Renvoie : avr
    MsgBox MonthName(5, True) 'Renvoie : mai
    MsgBox MonthName(6, True) 'Renvoie : juin
    MsgBox MonthName(7, True) 'Renvoie : juil
    MsgBox MonthName(8, True) 'Renvoie : août
    MsgBox MonthName(9, True) 'Renvoie : sept
    MsgBox MonthName(10, True) 'Renvoie : oct
    MsgBox MonthName(11, True) 'Renvoie : nov
    MsgBox MonthName(12, True) 'Renvoie : déc
    
End Sub