The VBA MonthName Function returns a string containing the month name, for a supplied month number.
The syntax of the function is:
Where the function arguments are:
Month | - | An integer, between 1 and 12, representing the month. | ||||||
[Abbreviate] | - |
An optional Boolean argument that specifies whether the returned month name should be abbreviated. This can have the value:
|
' Return the month name for month number 1 (Jan)
Dim mth1 As String
Dim mth2 As String
mth1 = MonthName( 1 )
mth2 = MonthName( 1, True )' mth1 is now equal to the string "January". ' mth2 is now equal to the string "Jan". |
After running the above VBA code, the variables mth1 and mth2 are equal to the Strings "January" and "Jan" respectively.
' Return the month name for the date 12/31/2015
Dim mth As String
' The variable mth now equals "December".
mth = MonthName( Month( #12/31/2015# ) ) |
Note that the above VBA code combines the MonthName function with the Month function, to return the month name for the date 12/31/2015.
Therefore, after running the above VBA code, the variable mth is equal to the String "December".