Can a date be generated based on another date in the document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a template we use and the currrent date is entered into a field and we
would like for another field to have a date in the future (months or years)
based on the current date
 
I would do this document in Excel where I know you can do this. Also
remember, Excel prints out just like Word does.
 
You can use the code below to do what you want:

ActiveDocument.FormFields("myDate").Result = _
Format((Date + 7), "m/d/yy")

To test the above code...add a TextBox form field into a document.
Double click the form field and set the bookmark name to myDate. Then
run this code. This will insert the date 7 days from now into the form
field.

If you are using a date field now, just remove that and insert a form
field and use the code as needed...modifying the + 7 to whatever
advanced days you need and "m/d/yy" to whatever format you want.

You can also do this with a bookmarked location. Insert a bookmark
where the date should go...then run your code. However, in that case
(if you use a bookmark), you'll need to use this version of the code,
since it's no longer a form field...

Selection.GoTo What:=wdGoToBookmark, Name:="myDate"
Selection.InsertAfter Format((Date + 7), "m/d/yy")

Note...for more info on Forms creation...see this link:

Word AutoForm Articles
http://www.mousetrax.com/techpage.html#autoforms

Dian D. Chapman, Technical Consultant
Microsoft MVP, MOS Certified
Editor/TechTrax Ezine

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 
This is more complex than you might imagine, but it can be done. See
http://addbalance.com/word/datefields2.htm for information on the different
kinds of ways to make a date calculation work. It includes links to pages
with fields and an explanation of different macros that can be used instead
of fields.

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Back
Top