Excel and events

  • Thread starter Thread starter Lumpjaw
  • Start date Start date
L

Lumpjaw

I would like to write to an event log named 'Trackers' that records a users
name and machine everytime a specific execl workbook is updated, can this be
done? How do I go about making the event log? Thanks

-lumpjaw
 
Hi

You would need to enter something like the following in a Workbook event
before save.
This will open a file called Tracker.txt in the same folder as the
workbook, and add a row with the relevant details for you.

This must be pasted into the ThisWorkbook module, NOT in a standard
module.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Open ThisWorkbook.Path & "\Trackers.txt" For Append As #1
Print #1, Environ("USERNAME") & "," &Environ("COMPUTERNAME") &
"," & Now
Close #1

End Sub

You can copy the code and paste it into your Visual Basic Editor
To do this,

Alt + F11 (open VBE)
Ctrl + R (open Project Explorer)
Select the file name on the left
Select This WorkBook
Paste code in Module


For more help on inserting macros
David McRitchie has lots of useful help on his site at
http://www.mvps.org/dmcritchie/excel/install.htm
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

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

Back
Top