MS Word, Use Auto-date (todays date) plus twenty one days

Posted on 2007-12-28
Medium Priority
Last Modified: 2012-08-14

i need to create a MS Word file; that when it open it has today's date (date file is opened) plus twenty-one days added to it.

Here's the code MS uses for Today's Date "{ DATE\@ M/d/yyyy }".

I'm just not sure where to insert the code to add twenty-one more days to the Today Date.

Question by:paulpp
  • 3
  • 2
LVL 22

Accepted Solution

Flyster earned 2000 total points
ID: 20546487
Hi Paul,

One of the things I really dislike about word is the lack of ability to add dates in fields. Here's one way to work around it. Create the following macro:

Sub AutoOpen()

  Selection.GoTo What:=wdGoToBookmark, Name:="DatePlus21"
  Selection.InsertBefore Format((Date + 21), "MMMM dd, yyyy")

End Sub

Now in your document place a bookmark in the spot where you want the date to appear. Name the bookmark DatePlus21. Now, when you open the document, the current date plus 21 days will appear at the bookmark. You can change the format to fit your needs.


Author Comment

ID: 20546633

can you create a sample file for me? is there anyway to do this without Micros?

Author Comment

ID: 20547143

okay, i see what you've done. but i need to place this code on a word doc that's being used as a label. so the date is being repeated about thirty times on the doc.

i can only get the bookmark to work in one instance and not all thirty places on the label.

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

LVL 76

Expert Comment

ID: 20547369
Bookmarks must have unique names to work properly.

There is no in-built date arithmetic in Word Fields, so you have to calculate when the day rolls over to the next month and the next year.

However, there are some brave people who do that sort of thing:

This site has a zipped Word document that you can download with many date calculations

Look for the field under "Calculate a day, date, month and year, using n days delay". Use the Alt + F9 toggle to see/hide the field codes. You can copy and paste it into your document, but we can only paste the result into here. It is pre-set to 14 days hence, so you need to edit that to a 1 when the code is visible. Don't forget that fields need to be updated to perform their calculation.

Note that it comprises an outer field with 32 other fields nested at various depths within it.

Alternatively you could use a macro like this:

Sub PlusThreeWeeks()
    Selection.Text = Format$(DateAdd("d", 21, Now), "Long Date")
End Sub

and set up a keystroke shortcut (Tools/Customize) to insert it.

It won't update each time the document is opened. Do you need that to happen?
LVL 22

Expert Comment

ID: 20548063
Here's a field code that will work for you:

{SET Delay 21}
{SET a(=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-
INT (b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT ((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
{=mm*10^6+dd*10^4+yy \# "00'-'00'-'00"} \@ "MMM d, yyyy"}

As Graham stated, it contains a series of nested fields. You can't just copy and paste it. At the end of each line is a hard return. The way to enter this is press ctrl+f9, type QUOTE and then press enter, then ctrl+f9 and type SET Delay 21. Move your cursor between the 2 remaining }} and press enter. This should leave you with one } on the 3rd line. Continue this to the end. The last piece of code( "MMM d, yyyy" ) is where you define the date format you want displayed.


Author Closing Comment

ID: 31417753

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question