Excel VBA Macros | Event handling exercise | Write a macro to log whenever anyone saves a file

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the course listed below!

Software ==> Excel VBA Macros  (52 exercises)
Version ==> Any version of Excel
Topic ==> Event handling  (4 exercises)
Level ==> Relatively easy
Course ==> Excel VBA macros
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Open the workbook in the above folder.  It contains a hidden sheet called Save log:

Log file

The hidden sheet contains a record of who has saved changes to the workbook, and when.

 

Attach a macro to an event for the workbook which adds another line to this hidden worksheet whenever anyone saves the file.  Here's what you can use for the two bits of data:

Column Use Returns
A - Date and time Now The current date and time
B - Author Environ("UserName") The logged-on user name

You may need to unhide the worksheet before writing to it, and you should certainly hide it again when you've finished.

When you've finished, save your file with the same name (this should write another line to the log sheet!), then close it down.

This page has 0 threads Add post