Microsoft Visual Basic
Event handling exercise
Average difficulty

This Microsoft Visual Basic EVENT HANDLING exercise is provided to allow potential course delegates to assess their suitability for the Wise Owl EXCEL 2007 VISUAL BASIC course only, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Exercise: Reacting to Excel events

A full answer to this exercise is provided as part of the training course!

1) Download the files needed to start this exercise: exercise-921.zip (and click here if you experience any problems unzipping this file after downloading it).
2) You are organising a lottery, and want to ensure that it is impossible to win any prize.  Firstly, assign a macro to the workbook in the above folder such that when a user opens it, they see this message:
Exercise screen-shot 2050 So far, so good ...
3) Assign a macro to an event for the Lottery worksheet such that if a user does click on the yellow cell, they see this message:
Exercise screen-shot 2051 Your macro could test whether the cell clicked on has address $C$8
4) Assign a macro such that if a user double-clicks on cell B16 to register a complaint, they see an irritating message telling them that the complaints facility is under construction (you can use the BeforeDoubleClick event to do this).
5) Your user will now probably click on the Alternative complaints procedure worksheet.  Assign a macro to a workbook event such that if he or she does this, they will see this message if they try to return to the Lottery sheet::
Exercise screen-shot 2052 On the SheetDeactivate event of the workbook, test the name of the sheet you are leaving, and if it is not the Lottery sheet return to it
6) Finally, just to complete your user's day display this message if the user tries to close the workbook:
Exercise screen-shot 2053 You could always add the Microsoft phone number for help ...
7) Save your macro as Annoying macros.xls, then close it down (if you can!).

Thank you for showing an interest in this Excel 2007 Visual Basic training course! As mentioned above, full answers to this and other exercises are provided on the course. On all Wise Owl scheduled courses delegates can take away these model answers (together with their own efforts!) on a free USB stick.

All content copyright Wise Owl Business Solutions Ltd 2008.  All rights reserved..