VBA - WeekDay Name


Advertisements

The WeekDayName function returns the name of the weekday for the specified day.

Syntax

WeekdayName(weekday[,abbreviate[,firstdayofweek]]) 

Parameter Description

  • Weekday − A required parameter. The number of the weekday.

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

  • Firstdayofweek − An optional parameter. Specifies the first day of the week.

    • 0 = vbUseSystemDayOfWeek - Use National Language Support (NLS) API setting

    • 1 = vbSunday - Sunday

    • 2 = vbMonday - Monday

    • 3 = vbTuesday - Tuesday

    • 4 = vbWednesday - Wednesday

    • 5 = vbThursday - Thursday

    • 6 = vbFriday - Friday

    • 7 = vbSaturday - Saturday

Example

Add a button and add the following function.

Private Sub Constant_demo_Click()
   msgbox("Line 1 : " &WeekdayName(3))
   msgbox("Line 2 : " &WeekdayName(2,True))
   msgbox("Line 3 : " &WeekdayName(1,False))
   msgbox("Line 4 : " &WeekdayName(2,True,0))
   msgbox("Line 5 : " &WeekdayName(1,False,1))
End Sub

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

Line 1 : Tuesday
Line 2 : Mon
Line 3 : Sunday
Line 4 : Tue
Line 5 : Sunday
vba_date_time.htm
Advertisements