VBA Code to add date

  • Thread starter Thread starter npereira
  • Start date Start date
N

npereira

Excellent!

This works like I needed it to.

Now, 1 more question. Is it possible to set the sheet to automaticl
insert todays date when I save the document? Instead of having to clic
that button?

This is for an Invoice Template I am setting up.

Thanks
 
There's a workbook_beforesave event that you can tap into.

Rightclick on the excel icon to the left of the File dropdown on the worksheet
menubar.

Select view code and paste this in that codewindow.

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Me.Worksheets("sheet1").Range("e11")
.Value = Date
.NumberFormat = "mmmm dd, yyyy"
End With
End Sub

Amend the worksheet name to what you want.
 

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

Back
Top