Audit Trail

R

Rich

I would like to build an audit trail into a spreadsheet so that anyone who
opens the file is is logged in a worksheet with user name and time stamp.
What's the easiest / best way to achieve this?
 
M

Mike H

Rich,

Alt+F11 to open VB editor. Double click 'ThisWorkbook' and paste the code
below in on the right. It uses a worksheet called "Audit"

Private Sub Workbook_Open()
Dim LastRow As Long
Set sht = Sheets("Audit")
LastRow = sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
sht.Cells(LastRow, 1) = Environ("Username")
sht.Cells(LastRow, 2) = Now
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
M

Mike H

Hi,

In case the user doesn't save it may be a good idea to save it with the
openers username by making this the last line in the code

ActiveWorkbook.Save
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 

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

Top