Microsoft KB Archive/105536

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 08:56, 20 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

WD: How to Determine the Number of Days in a Specified Month

Q105536



The information in this article applies to:


  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows, versions 7.0, 7.0a





SUMMARY

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.

The macro takes leap years into consideration when computing the number of days in the month of February.

   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.