WD: How to Determine the Number of Days in a Specified Month |
Q105536
To determine the number of days in a specified month, use the following
Microsoft WordBasic macro Select Case structure.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN
RISK. Microsoft provides this macro code "as is" without warranty of any
kind, either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
Sub Main
'This macro determines the number of days in a given month.
datev = DateValue(InputBox$("Enter a date in the mm/dd/yy format"))
mon = Month(datev)
Select Case mon
Case 1, 3, 5, 7, 8, 10, 12
MsgBox "31 days"
Case 4, 6, 9, 11
MsgBox "30 days"
Case 2
mon = Month(datev)
If Year(datev) Mod 4 = 0 Then
MsgBox "There are 29 days in this month"
Else
MsgBox "There are 28 days in this month"
End if
End Select
End Sub
This macro prompts for a date in the mm/dd/yy format and returns
the number of days in the specified month. The Month function is used
to determine the month number for the specified date. Then depending
on the month number (1-12), a message box posts the number of days in
the month.
If Year(datev) Mod 4 = 0 Then
The year is divided by 4 and if the remainder is 0, the number of days
in the month is 29 days.
Additional query words: month day datevalue
Keywords : kbmacro kbmacroexample winword word6 word7 word95
Issue type :
Technology :
|
Last Reviewed: November 4, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |