VBA Events
VBA Events
VBA - EVENTS
https://www.tutorialspoint.com/vba/vba_events.htm Copyright © tutorialspoint.com
VBA, an event-driven programming can be triggered when you change a cell or range of cell values manually.
Change event may make things easier, but you can very quickly end a page full of formatting. There are two kinds
of events.
Worksheet Events
Workbook Events
Worksheet Events
Worksheet Events are triggered when there is a change in the worksheet. It is created by performing a right-click
on the sheet tab and choosing 'view code', and later pasting the code.
The user can select each one of those worksheets and choose "WorkSheet" from the drop down to get the list of all
supported Worksheet events.
Following are the supported worksheet events that can be added by the user.
Example
Let us say, we just need to display a message before double click.
https://www.tutorialspoint.com/cgi-bin/printpage.cgi 1/3
7/12/2017 VBA Events
End Sub
Output
Upon double-clicking on any cell, the message box is displayed to the user as shown in the following screenshot.
Workbook Events
Workbook events are triggered when there is a change in the workbook on the whole. We can add the code for
workbook events by selecting the 'ThisWorkbook' and selecting 'workbook' from the dropdown as shown in the
following screenshot. Immediately Workbook_open sub procedure is displayed to the user as seen in the
following screenshot.
Following are the supported Workbook events that can be added by the user.
https://www.tutorialspoint.com/cgi-bin/printpage.cgi 2/3
7/12/2017 VBA Events
Example
Let us say, we just need to display a message to the user that a new sheet is created successfully, whenever a new
sheet is created.
Output
Upon creating a new excel sheet, a message is displayed to the user as shown in the following screenshot.
https://www.tutorialspoint.com/cgi-bin/printpage.cgi 3/3