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.

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 77

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

621 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