I would like to run a macro just before Windows shutsdown
to log the time.
I wrote below program to run the macro just right after windows
starts up. I will put the shortcut
in Windows startup
folder so that when windows starts, it will log
the current day time and date.
But how to run a macro just before shutting down the PC.
The same below code will work for Start up
and shut down
with little change
.
But how to run the macro or code
before windows turns off
Private Sub Workbook_Open()
'
' Macro1 Macro
'
Dim Day As Date
Dim Tim As Date
Dim Row As Integer
Dim Col As Integer
Row = 1
Col = 1
Day = DateValue(Now)
Tim = TimeValue(Now)
While (Cells(Row, Col) <> "")
Row = Row + 1
Wend
Cells(Row, Col) = Day
Cells(Row, Col + 1) = Tim
ThisWorkbook.Save
'
End Sub