Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Determining the Month of the Year.
by Allen Wyatt
(last updated October 15, 2016)
When creating macros in VBA, you may have a need to know the specific month of the year, as represented by a particular date. For instance, you may want to determine the month in which the macro is being executed. The following code will do the trick:
iMonth = Month(Now())
The Month function returns an integer value representing the numeric month of whatever date you provide. In this example, the Now function represents today's date, and so Month returns the current month, as a value ranging from 1 to 12.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12343) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Determining the Month of the Year.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
ScreenTips can appear with or without shortcut keys displayed in them. Here's how to control whether they appear or not.Discover More
When writing a macro, you may need a way to clear the undo stack. This can be done with a single command, as described in ...Discover More
Word apparently has a bug in it that makes it very difficult to remove a shortcut key previously associated with a macro. ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.