
Tips.Net > WordTips Home > Macros > WordBasic Examples > Calculated Dates with WordBasic
Summary: Wanna do date math? Here's how to do it in WordBasic. (This tip works with Microsoft Word 6, and Word 95.)
You may wonder if there is a quick way to put a calculated date into a letter created in Word. For instance, you may want to send out mail-merged letters with a date that is 30 days after the date on which the letters were created.
Unfortunately, there is no native way to do this in Word. For instance, there is no field code you can use to insert a calculated date. If you are using Excel or Access as your data source for the mail merge, the simplest solution may be to just add a field in the data source that shows the calculated date. (It is very easy to do this in both Excel and Access.) The data source field can then be placed in the mail-merge document and everything is set.
If you want to stick with Word and cannot modify the data source (perhaps someone else supplies it), then you can use a macro to insert the future date. The following WordBasic macro will do the trick:
Sub MAIN
Insert Date$(Today() + 30)
End Sub
This macro determines today's date, adds 30 days to it, formats it according to the default formatting set up in Word, and inserts it into the document. If you assign this macro to a shortcut key, you can quickly insert your future date whenever you want.
Tip #809 applies to Microsoft Word versions: 6 95
More Power! For some people, the prospect of creating Word macros can be scary. WordTips: The Macros can help you conquer your fears and you'll discover you're much more confident and productive as you make Word do exactly what you want. This is an invaluable source for learning macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of WordTips. Learn at your own pace, exactly the way you want.
Check out WordTips: The Macros today!
Word includes two powerful search engines. Do you know how to use them both? You can discover new knowledge with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Word2007 Tips
WordTips