Excel log

mani06ah

New Member
Joined
Nov 2, 2017
Messages
3
Hi all,

I was wondering if there is any way to create a simple log in excel, that logs the date and time of opening and closing of Office files? Do any of you guys have any idea on how to do that?

Thank you in advance

Best regards
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
In Excel press Alt+F11 to open the VBA editor

copy the below code into the thisworkbook module of your workbook. the workbook must be saved as a file type that allows macros such as .xlsm

Note this code will save the file on close so that the date stamp is saved. If you want to close with out saving you will need to either stop macros from running or comment out the save command.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lr As Long
lr = Sheets("log").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("log").Cells(lr + 1, 1) = "closed"
Sheets("log").Cells(lr + 1, 2) = Now
ActiveWorkbook.Save
End Sub

Code:
Private Sub Workbook_Open()

Dim lr As Long
lr = Sheets("log").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("log").Visible = xlVeryHidden 'assuming you do not want people to see the log
Sheets("log").Cells(lr + 1, 1) = "Opened"
Sheets("log").Cells(lr + 1, 2) = Now
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,734
Messages
6,132,418
Members
449,727
Latest member
Aby2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top