Inserting Date

E

Elaine J.

I want to create a macro (assigned to Control Z). that simply inserts the
current date into a document. I have looked at the date function and it
seems like it would be really easy, but for some reason I cannot come up with
the correct syntax. My user wants mm/dd/yyyy format.

Can someone help me with that?

Thanks.
 
G

Graham Mayor

CTRL+Z is the undo command? It might be better to choose another!

Sub InsertUSFormatDate()
If Documents.Count = 0 Then
MsgBox "Open a document first", vbCritical, "No Document"
Exit Sub
End If
With Selection
.InsertDateTime DateTimeFormat:="MM/dd/yyyy", InsertAsField:=False
End With
End Sub

http://www.gmayor.com/installing_macro.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Fumei2 via OfficeKB.com

Totally agree using Ctrl-Z is not a good idea.

If you simply want the current date in the document AND you want that date to
update with whatever is the current date, then maybe use a DATE field.
Insert > Field and select the Date field. You can set it for whatever format
you want.



Graham said:
CTRL+Z is the undo command? It might be better to choose another!

Sub InsertUSFormatDate()
If Documents.Count = 0 Then
MsgBox "Open a document first", vbCritical, "No Document"
Exit Sub
End If
With Selection
.InsertDateTime DateTimeFormat:="MM/dd/yyyy", InsertAsField:=False
End With
End Sub

http://www.gmayor.com/installing_macro.htm
I want to create a macro (assigned to Control Z). that simply inserts the
current date into a document. I have looked at the date function and it
[quoted text clipped - 5 lines]
 

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