Static Date code for macro

F

fenixdood

Hi,

I have been asked to modify one of our Word Macros so that the date
stays static. Currently we are using
{ DATE \@ "MMMM d, yyyy" \*MERGEFORMAT }
This is fine but when ever the document is opened again the date
changes to the current date and not the one that was supposed to be
for the Originating Date..

Could someone perhaps point me to the right place to get this
answered...

PS not a Macro or VBA expert by any means but do have scripting under
my belt...

Cheers an TIA

Ron
 
G

Graham Mayor

This has little to do with macros.

The obvious solution would be to change the DATE field in the document
template to a CREATEDATE field. CREATEDATE always shows the date it was
created in the template and the dates the documents created from that
template will show they dates they were created. The \*MERGEFORMAT switch
is superfluous here and can be removed from the field. Thus { CREATEDATE \@
"MMMM d, yyyy" }


If you are inserting the date from a macro then fields need not come into it
at all eg

Sub InsertUSFormatDate()
With Selection
.InsertDateTime DateTimeFormat:="MMMM" & Chr(160) & _
"d," & Chr(160) & "yyyy", InsertAsField:=False
End With
End Sub

will insert the current date as text at the cursor.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jay Freedman

fenixdood said:
Hi,

I have been asked to modify one of our Word Macros so that the date
stays static. Currently we are using
{ DATE \@ "MMMM d, yyyy" \*MERGEFORMAT }
This is fine but when ever the document is opened again the date
changes to the current date and not the one that was supposed to be
for the Originating Date..

Could someone perhaps point me to the right place to get this
answered...

PS not a Macro or VBA expert by any means but do have scripting under
my belt...

Cheers an TIA

Ron

The usual answer is to use a CREATEDATE field instead of a DATE field. That
will always display the date the document was created, either by making a
new document based on the template or by using Save As from an existing
document.

If the creation date isn't what you want, you can instead either lock or
unlink the DATE field when it's showing the correct date. Locking the field
(in code, if the variable myField points to the DATE field in question,
execute myField.Locked = True) prevents the field from updating until you
unlock it. Unlinking the field (in code, execute myField.Unlink) replaces
the field with the plain text of its current value, which of course will
never update.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
F

Fenixdood

Thanks for the info..

caviat is...I used the CreateDate but it inputs the date the template was
created. I am in need of a user who creates a new document from template.
then the date is hard coded immediatley and will not change..

not too sure how the VB code should be on this one.. can you help out..?.

Cheers
Ron
 
J

Jay Freedman

In the template itself, the CreateDate field will show the template's date of
creation. When you base a new document on the template, it _will_ show the
document's date of creation, not the template's.

Of course it would be possible to write an AutoNew macro to insert the current
date as plain text, but that would be reinventing the wheel because the
CreateDate field does exactly what you're asking for.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
F

Fenixdood

Thanks for your insight..

My Findings..firstly I am new to this Company and still learning how they
operate..
So..the documents in question are not .dot but rather.doc..we use an
application (ms access based) and then generate letters using mail merge,
pulling data from the DB and then into a letter in word.
I changed the format of the document i am testing to a .dot. and it seems
the date field appears..So i take it that the letters which are in .doc
format need to be in .dot format.. do you think I have this correct?

TIA
Ron
 
J

Jay Freedman

You may be correct, but I have no idea what your Access application is doing so
I can't be sure. I think the only way you'll find out is to try it.

Generally, a CreateDate field in a document will show the correct date if (a)
the document is created by the File > New command (or its VBA equivalent,
Documents.Add) based on a template, or (b) you use File > Save As (or its VBA
equivalent) to make a copy of an existing document.

If the Access application does one of these two things, then the field should
work. If you can't get it to work, the best alternative will be to alter the
Access application to insert the current date in the document (probably at a
predefined bookmark) as plain text. Unfortunately, I can't help much with that.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
F

Fenixdood

Thanks for your help jay...Seems to be working now... one thing is do you now
what I need to do to have the Date displyed in bold font..it was bold before
I adjusted things now the text is simple font..I am looking for a clue...

Regards
R
 

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