PDA

View Full Version : Insert today's date, save file and close



Ryans
06-13-2008, 06:08 AM
Hi,

I need help to write a macro that, upon press of a button, the date in a specific cell updates to today's date and then the file is saved and closed.

Thanks

grichey
06-13-2008, 06:17 AM
Insert something like this into your button code:

sub addtime
Range("A1").Select 'where A1 is your "specific cell"
Selection=NOW()
End sub

xluser2007
06-13-2008, 06:59 AM
Try the following code.

You need to add the button, go to "Design Mode" on the VBA toolbar.

Then right click the button and go to "View Code" and insert the routine below, without the sub, End Sub commands.


Option Explicit

Sub InsertDate_Close_and_Save_Activeworkbook()

'The following Sheet reference will need to be changed to suit
ActiveWorkbook.Sheets(1).Range("A1").Value = Format(Now, "d/mm/yyyy h:mm") '<= Change format of Time Stamp to suit

' This will close and save the Activeworkbook
ActiveWorkbook.Close savechanges:=True

End Sub


regards,