Jennifer has a form letter that she sends out periodically. If the date that she prints the letter is within the last week of the month, she has a special notice she would like included near the beginning of the letter. If it is not the last week of the month, the notice should not appear. Jennifer wonders if there is a way to include the notice automatically based on the date.
The easiest way to accomplish this task is by combining a macro, typically run when the document is first opened, to set a document variable. Then, you can use a field to evaluate the document variable and insert a notice that is stored in a Building Block.
The first task for Jennifer is to create her special message and store it in a Building Block called something catchy, such as MonthEndNotice. The notice can contain just about anything that should be displayed during the last week of the month.
Next, a simple macro needs to be created that sets the document variable. Here's an example:
Sub IncludeNotice()
Dim d As Date
Dim LastDay As Date
d = Date
LastDay = DateSerial(Year(d), Month(d) + 1, 0)
If LastDay - d < 7 Then
ActiveDocument.Variables("ShowNotice").Value = "1"
Else
ActiveDocument.Variables("ShowNotice").Value = "0"
End If
ActiveDocument.Fields.Update
End Sub
Again, this macro should be run each time the document is opened. It determines today's date (in the d variable) and then calculates the last day of the month. If d is within the last week of the month, then the ShowNotice variable is set to 1, otherwise to 0.
Now, within the document, you can use the following compound field where you want the notice, if appropriate, to appear:
{ IF { DOCVARIABLE ShowNotice } = "1" { AUTOTEXT "MonthEndNotice" } "" }
Each set of braces in this field should be entered using the Ctrl+F9 shortcut. The DOCVARIABLE field returns whatever is in the ShowNotice document variable, a value set by the macro. If it is equal to 1, then the IF field executes the AUTOTEXT field, which returns the content of the MonthEndNotice Building Block. If ShowNotice is any value other than 1, then an empty string ("") is returned.
The last line of the macro updates fields in the document, but you may want to update them manually before actually printing your document. The desired special notice should appear only if the current date is within the last week of the month.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9810) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.
Do More in Less Time! An easy-to-understand guide to the more advanced features available in the Microsoft 365 version of Word. Enhance the quality of your documents and boost productivity in any field with this in-depth resource. Complete your Word-related tasks more efficiently as you unlock lesser-known tools and learn to quickly access the features you need. Check out Microsoft 365 Word For Professionals For Dummies today!
Need to know if a number in a macro is odd or even? It's easy to figure out with the simple calculation shown in this tip.
Discover MoreYour macro may need to determine if the user has overtype mode turned on. You can find out the overtype status easily by ...
Discover MoreIf you are applying formatting from within a macro, you may want to change the alignment of various paragraphs. Here's ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments