VBA - Month Name



The MonthName function returns the name of the month for the specified date.

Syntax

MonthName(month[,toabbreviate]) 

Parameter Description

  • Month − A required parameter. It specifies the number of the month.

  • Toabbreviate − An optional parameter. A Boolean value that indicates if the month name is to be abbreviated. If left blank, the default value would be taken as False.

Example

Add a button and add the following function.

Private Sub Constant_demo_Click()
   msgbox("Line 1 : " & MonthName(01,True))
   msgbox("Line 2 : " & MonthName(01,false))
   msgbox("Line 3 : " & MonthName(07,True))
   msgbox("Line 4 : " & MonthName(07,false))
End Sub

When you execute the above function, it produces the following output.

Line 1 : Jan
Line 2 : January
Line 3 : Jul
Line 4 : July
vba_date_time.htm
Advertisements