560 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Event-handling macros in Excel Visual Basic Part five of a five-part series of blogs |
---|
Want to do something when a user opens a workbook, or stop them clicking on a particular cell? You need to learn how to attach code to Excel workbook or worksheet events!
This series of blogs is part of our Excel VBA online tutorial. If you want to learn more, have a look at our classroom-based courses in VBA macros and/or Excel.
|
Although this blog is mainly about Excel VBA, I thought I'd briefly show how events work in various other Microsoft Office applications. I've used Office 2010 for all of the examples on this page, but the ideas would work just as well in Office 2007.
Microsoft Word follows pretty much the same pattern as Microsoft Excel:
You can double-click on ThisDocument to attach code to an event for the document.
The list of events available isn't as rich as it is for Excel:
The list of events doesn't include BeforeClose, for example.
There is a way to create additional events for Word using something called an event sink, but it's scary stuff, and you'll need to understand classes to work out what's going on.
PowerPoint doesn't allow you to attach code to events easily:
There is a presentation open, but you can't see that in Project Explorer.
However, as for Word there is a way to attach code to events for a presentation by creating something called an event sink (see above).
Even if you do create a PowerPoint event sink, you still won't have truly solved the problem, as you still need something to run a macro to create the event sink in the first place!
The whole of Access form and report design is based around the concept of events:
This diagram shows the events available for a simple label control (a bit of text stuck on a form).
Whereas events in Excel, Word and PowerPoint are optional extras, you won't be able to write VBA code in Access forms or reports without using them all the time.
The events which can occur in an Outlook session are shown below:
Want to create a rule for how new mail should be treated? Don't bother with the Outlook rules - why not create your own in VBA!
Outlook macros are all held in a single file with an .OTM extension.
As the above examples show, handling events in Excel VBA is - as is so often the case - easier than doing the same thing in other MS Office applications.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.