VBA WEEKDAYNAME Function - ExcelFunctions.net

文章推薦指數: 80 %
投票人數:10人

The VBA WeekdayName Function returns a string containing the weekday name, for a supplied integer representation of a weekday. ExcelFunctions.netSearchSite: + Home»VBA-Functions»VBA-WeekdayName-FunctionTheVBAWeekdayNameFunction RelatedFunction:VBAWeekdayDescriptionTheVBAWeekdayNameFunctionreturnsastringcontainingtheweekdayname,forasuppliedintegerrepresentationofaweekday.Thesyntaxofthefunctionis:WeekdayName(Weekday,[Abbreviate],[FirstDayOfWeek])Wherethefunctionargumentsare:Weekday-Aninteger,between1and7,representingthedayoftheweek.(Notethattheweekdaythatisrepresentedbyeachintegervaluedependsonthevalueofthe[FirstDayOfWeek]argument).[Abbreviate]-AnoptionalBooleanargumentthatspecifieswhetherthereturnedweekdaynameshouldbeabbreviated.Thiscanhavethevalue:True-Returnabbreviatedweekdayname(i.e."Sun","Mon","Tue",etc.)False-Returnfullweekdayname(i.e."Sunday","Monday","Tuesday",etc.)Ifthe[Abbreviate]argumentisomitted,itissettothedefaultvalueFalse.[FirstDayOfWeek]-AnoptionalFirstDayOfWeekenumerationvalue,specifyingtheweekdaythatshouldbeusedasthefirstdayoftheweek.Thiscanhaveanyofthefollowingvalues:vbUseSystemDayOfWeek-ThefirstdayoftheweekisasspecifiedinyoursystemsettingsvbSunday-SundayvbMonday-MondayvbTuesday-TuesdayvbWednesday-WednesdayvbThursday-ThursdayvbFriday-FridayvbSaturday-SaturdayIfomitted,the[FirstDayOfWeek]argumentusesthedefaultvaluevbSunday.VBAWeekdayNameFunctionExamplesExample1-ReturntheWeekdayNameforaGivenWeekdayNumber'Returntheweekdaynameforweekdaynumber1'(firstdayofweeksettodifferentvalues)Dimwkday1AsStringDimwkday2AsStringDimwkday3AsStringwkday1=WeekdayName(1)'wkday1isnowequaltothestring"Sunday".wkday2=WeekdayName(1,True)'wkday2isnowequaltothestring"Sun".wkday3=WeekdayName(1,True,vbMonday)'wkday3isnowequaltothestring"Mon".Notethat,intheaboveexamples:InthefirsttwocallstotheWeekdayNamefunction,the[FirstDayOfWeek]argumentisomitted.ThisisthereforesettothedefaultvaluevbSunday(i.e.weekdaynumber1isSunday).InthethirdcalltotheWeekdayNamefunction,the[FirstDayOfWeek]issettovbMonday(i.e.weekdaynumber1isMonday).Therefore,afterrunningtheexamplecode,thevariableswkday1,wkday2andwkday3areequaltotheStrings"Sunday","Sun"and"Mon"respectively.Example2-ReturntheWeekdayNameforaGivenDate'Returntheweekdaynameforthedate12/31/2015DimwkdayAsStringwkday=WeekdayName(Weekday(#12/31/2015#))'Thevariablewkdaynowequals"Thursday".TheaboveVBAcodecombinestheWeekdayNamefunctionwiththeWeekdayfunction,toreturntheweekdaynameforthedate12/31/2015.Therefore,afterrunningtheaboveVBAcode,thevariablewkdayisequaltotheString"Thursday". ReturntotheVBAFunctionsPageReturntotheExcelVBATutorialPageHomeBasicExcelBuilt-InExcelFunctions ▾ListofAllExcelFunctionsTextFunctionsLogicalFunctionsInformationFunctionsDate&TimeFunctionsLookup&ReferenceFunctionsMathFunctionsStatisticalFunctionsDatabaseFunctionsFinancialFunctionsEngineeringFunctionsExcel2019NewFunctionsExcel2016NewFunctionsExcelVlookupTutorialPivotTableTutorialExcelFormulasArrayFormulasAccountinginExcelTips&TricksCommonExcelErrorsExcelTemplatesExcelMacrosExcelVBATutorialBuilt-InVBAFunctionsExcel2003vs2007 Disclaimer PrivacyPolicy CookiesPolicyCopyright©2008-2021ExcelFunctions.net



請為這篇文章評分?