Word VBA, Date Format

When writing dates to a word document you could specify a specific format. For example consider the code below:

Sub main()
Range.Text = Date
End Sub

It prints the current date to the document:

Word VBA, Date
We can change the way the date is output using the code below:

Sub example2()
Range.Text = Format(Date, "MMMM DD, YYYY ")
End Sub

Result:

Word VBA, Date, Format

In the table below you can see the result of using different formattings for outputting date values:

Format Result
MMMM DD, YYYY May 05, 2014
MM DD, YYYY 05 05, 2014
M D, YYYY 5 05, 2014
MMMM D, YYYY May 5, 2014
MMMM D, YY May 5, 14
DDDD MMMM DD, YYYY Monday May 5, 14
DD MMMM DDDD, YY 05 May Monday, 14
YYYY, MMMM, DD 2014, May, 05

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Leave a Reply

Your email address will not be published. Required fields are marked *