Dates problem

J

Jack Schitt

Hi all

Background:
I am experienced at writing VBA macros for Excel but have NEVER written a
VBA macro for Word (although I have some colleagues at work who have done so
just by using the keystroke recorder).

Problem
I wish to create a template document that will automatically insert the
system date into a particular location of the template. However the date
must not dynamically update each time the saved document is opened. It must
be hard-coded at the time that the template is opened.

As I see it there are two parts to the problem: (1) setting the location in
the document at which the date is to be inserted and then (2) identifying
the current system date and then hard coding into the location identified.

Any pointers would be appreciated.

Thanks
 
C

Charles Kenyon

Identifying the point for insertion is up to you. It can be in a header or
footer or someplace in the body marked with a bookmark. Insertion is easy.
You can use a vba date function or insert a CREATEDATE field. If it will
always go the same place in the document, why not simply put in a CREATEDATE
field there and skip the coding? A createdate field in a template is updated
when a new document is created from the template and then not updated again
(unless someone uses SaveAs to save it).

See http://addbalance.com/word/datefields1.htm for information on the
different kinds of datefields and how to format them.
 
H

Helmut Weber

Hi Jack,
and besides of what Charles suggested,
you certainly wouldn't want to insert the date
into the template, but into the document,
that is created from it.
 
J

Jack Schitt

Thanks Charles and Helmut. You solved it.

--
Return email address is not as DEEP as it appears
Charles Kenyon said:
Identifying the point for insertion is up to you. It can be in a header or
footer or someplace in the body marked with a bookmark. Insertion is easy.
You can use a vba date function or insert a CREATEDATE field. If it will
always go the same place in the document, why not simply put in a CREATEDATE
field there and skip the coding? A createdate field in a template is updated
when a new document is created from the template and then not updated again
(unless someone uses SaveAs to save it).

See http://addbalance.com/word/datefields1.htm for information on the
different kinds of datefields and how to format them.

Jack Schitt said:
Hi all

Background:
I am experienced at writing VBA macros for Excel but have NEVER written a
VBA macro for Word (although I have some colleagues at work who have
done
 
J

Jack Schitt

I now think that I am looking for a solution that hard codes the date as a
string of text characters, because I do not want the date to recalculate to
the current system date if choosing "Save As". The ONLY time that the date
should reflect the current system date is upon opening the template. Any
help with that? Thanks.

--
Return email address is not as DEEP as it appears

Charles Kenyon said:
Identifying the point for insertion is up to you. It can be in a header or
footer or someplace in the body marked with a bookmark. Insertion is easy.
You can use a vba date function or insert a CREATEDATE field. If it will
always go the same place in the document, why not simply put in a CREATEDATE
field there and skip the coding? A createdate field in a template is updated
when a new document is created from the template and then not updated again
(unless someone uses SaveAs to save it).

See http://addbalance.com/word/datefields1.htm for information on the
different kinds of datefields and how to format them.

Jack Schitt said:
Hi all

Background:
I am experienced at writing VBA macros for Excel but have NEVER written a
VBA macro for Word (although I have some colleagues at work who have
done
 
D

Doug Robbins

A createdate field in the template will cause the date upon which a document
is created from that template to appear in that document in a form that does
not change when the document is saved or printed. If you want to convert it
to a string, you can select it and used Ctrl+Shift+F9. But then it can be
altered manually and may no longer display the date upon which the document
was actually created.

Selection.InsertBefore Format(Date, "MMMM d, yyyy")

will also insert the date as a string at the location of the cursor when a
macro containing that code is run.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Jack Schitt said:
I now think that I am looking for a solution that hard codes the date as a
string of text characters, because I do not want the date to recalculate
to
the current system date if choosing "Save As". The ONLY time that the
date
should reflect the current system date is upon opening the template. Any
help with that? Thanks.
 
J

Jack Schitt

Thanks Doug, I think this is just what I wanted. I am not bothered about
the fact that a text string can be edited. It would be hard to do
accidentally, so if it were changed manually I will assume that it was
intentional. I appreciate that if you wanted to prohibit a deliberate
change then that would be another matter, but this fear does not apply to my
application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top