The VBA MonthName Function

Related Function:
VBA Month

Description

The VBA MonthName Function returns a string containing the month name, for a supplied month number.

The syntax of the function is:

MonthName( Month, [Abbreviate] )

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:

True - Return abbreviated month name (i.e. "Jan", "Feb", "Mar", etc.)
False - Return full month name (i.e. "January", "February", "March", etc.)
If the [Abbreviate] argument is omitted, it takes on the default value False.


VBA MonthName Function Examples

Example 1 - Return the Month Name for a Given Month Number

' Return the month name for month number 1 (Jan)
Dim mth1 As String
Dim mth2 As String
mth1 = MonthName( 1 )
' mth1 is now equal to the string "January".
mth2 = MonthName( 1, True )
' 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.


Example 2 - Return the Month Name for a Given Date

' Return the month name for the date 12/31/2015
Dim mth As String
mth = MonthName( Month( #12/31/2015# ) )
' The variable mth now equals "December".

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".