Use VBA to set word custom doc property to current date

S

stercorum

I want to use VBA to change a CustomDocumentProperty Value to the current
date (month and year only).

My reason is in order to automate hidden publication dates stored in the
document at the point of compiling a PDF. I will run the VBA from a toolbar
button just prior to compiling the PDF.

Does anybody know how I can do this?
 
M

macropod

Hi stercorum,

Assuming you've defined the custom property "DocDate", you could set its
value with:
ActiveDocument.CustomDocumentProperties("DocDate") = Format(Date, "MM-YYYY")

You can then access the property in your document via a DocProperty field.
The above would return 06-2006.

As an aside, if all you're after is the current date formatted as month and
year, you could use any one of a DATE, CREATEDATE, SAVEDATE or PRINTDATE
field, according to your requirements and format it to display only the
month and year, with no need to use vba or Custom Document Properties. For
example:
{DATE \@ "MM-YYYY"}
would also return 06-2006

Cheers
 
S

stercorum

Excellent, thanks. I knew the answer had to be simple, but without your
assistance I might never have discovered it.

macropod said:
Hi stercorum,

Assuming you've defined the custom property "DocDate", you could set its
value with:
ActiveDocument.CustomDocumentProperties("DocDate") = Format(Date, "MM-YYYY")

You can then access the property in your document via a DocProperty field.
The above would return 06-2006.

As an aside, if all you're after is the current date formatted as month and
year, you could use any one of a DATE, CREATEDATE, SAVEDATE or PRINTDATE
field, according to your requirements and format it to display only the
month and year, with no need to use vba or Custom Document Properties. For
example:
{DATE \@ "MM-YYYY"}
would also return 06-2006

Cheers
--
macropod
[MVP - Microsoft Word]


stercorum said:
I want to use VBA to change a CustomDocumentProperty Value to the current
date (month and year only).

My reason is in order to automate hidden publication dates stored in the
document at the point of compiling a PDF. I will run the VBA from a toolbar
button just prior to compiling the PDF.

Does anybody know how I can do this?
 

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