automatically update time when i click save in excel

June 15, 2012 at 07:02:16
Specs: Windows XP
hi all, i want to automatically update date the document was saved when i click save on the excel tab and i have this macro but it does not work Any help please?
Sub Se()


If Worksheets("Sheet1").Range("a1") <> vbNullString Then Worksheets("Sheet1").Range("a1").Value = Time

End Sub

See More: automatically update time when i click save in excel

June 16, 2012 at 07:03:25
I know very little about VBA, but I do know that SET is a key word,
and is used to assign a reference to an object.

So your Sub Set() won't work.

Try using Sub MyTimeSet()

Also, for this Macro to function,
Cell A1 on Sheet 1 must NOT be blank.


Report •

June 18, 2012 at 07:09:12
You should tell us what you mean by "i have this macro but it does not work ".

What isn't working? Are you getting an error? Is it not updating the time? Something different?

A few things I see...

1 - You say that you want "to automatically update date the document was saved", yet you are using the Time function not the Date function.

2 - You are saving the workbook and then setting the time in A1. That seems backward to me. I'd have the code put the Date/Time in the cell before the Save, otherwise the Date/Time that will be saved will be the Date/Time from right after the previous Date/Time that the file was saved.

3 - This appears to be a macro that needs to be manually run. You might want to consider using the BeforeSave event in the ThisWorkbook module.

The BeforeSave event fires automatically each time you Save the workbook and runs the instructions found within the macro before the Save occurs.

4 - Why are you checking A1 for vbNullString? If you want the Date/Time in the cell, you won't get it if A1 is blank. Leave out the IF so that the Date (or in your case, the Time) will be placed in the cell every time, reagardless of whether A1 is blank or not the time of the Save.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question