Excel 5.0 Events

The versions of Excel before Excel 97 also supported events although these events had to be explicitly defined.
For compatibility reasons these methods are still supported although they should not be used now.
VBA > Macros > Excel 5.0 Macros.


OnSheetActivate

This event runs whenever the user switches to a sheet in the workbook.
You can set this event for any of the following objects:

' any sheet in the application
Application.OnSheetActivate = "Macro_Name"
'any sheet in the workbook
Workbook.OnSheetActivate = "Macro_Name"
' a specific sheet
Worksheet.OnSheetActivate = "Macro_Name"

These have been replaced with the following events:

Application.SheetActivate 
Workbook.SheetActivate
Worksheet.Activate

OnSheetDeactivate

This event runs after a sheet has been deselected.

' any sheet in the application
Application.OnSheetDeactivate = "Macro_Name"
'any sheet in the workbook
Workbook.OnSheetDeactivate = "Macro_Name"
' a specific sheet
Worksheet.OnSheetDeactivate = "Macro_Name"

Using Activesheet or Activeworkbook in this event can cause unexpected results.
These have been replaced with the following events:

Application.SheetDeactivate 
Workbook.SheetDeactivate
Worksheet.Deactivate

OnWindow

This event runs whenever the user switches to a specific window.

' any sheet in the application
Application.OnWindow = "Macro_Name"
' a specific window is activated
Windows("MyWbk.xls").OnWindow ="Macro_Name"

You can disassociate this event handler by assigning an empty string to the OnWindow property

Application.OnWindow = "" 

These have been replaced with the following events:

Application.WindowActivate 
Workbook.WindowActivate
Worksheet.Activate

The equivalent deactivate events are also available:

Application.WindowDeactivate 
Workbook.WindowDeactivate
Worksheet.Deactivate

OnCalculate

This event runs immediatley after a worksheet is recalculated.

Application.OnCalculate = "Macro_Name" 
Workbook.OnCalculate = "Macro_Name"

You can disassociate this event handler by assigning an empty string to the OnCalculate property

Application.OnCalculate = "" 

These have been replaced with the following events:

Application.SheetCalculate 
Workbook.SheetCalculate
Worksheet.Calculate

OnEntry

This event runs when a user enters some data onto a worksheet.

Application.OnEntry = "Macro_Name" 
Workbook.OnEntry = "Macro_Name"

This event occurs after the user enters the data and presses Enter or selects another cell.
The event will not occur if the user selects (Edit > Cut), (Edit > Paste) or if another procedure changes the contents of the cells.
These have been replaced with the following events:

Application.SheetChange 
Workbook.SheetChange
Worksheet.Change

OnData

This runs when new data arrives from an application other than Excel.

Application.OnData = "Macro_Name" 
Workbook.OnData = "Macro_Name"

This property is also available from some other objects that handle the arrival of data linked through DDE, object linking or embedding.
The OnData event does not run if it is linked to another running instance of Excel.
These have been replaced with the following events:

Application.SheetChange 
Workbook.SheetChange
Worksheet.Change

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext