You can't assign event handlers to macros. You have to use the
event handling code itself. Create a class module named
CExcelEvents with code like the following:
Public WithEvents XL As Excel.Application
Private Sub XL_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)
' your event handler code here
End Sub
Then, in your start up code, instantiate that class and assign
your Excel application reference to the XL variable in the class.
E.g., in a standard code module,
Dim XLEvents As CExcelEvents
Sub StartExcelEvents()
Set XLEvents = New CExcelEvents
Set XLEvents.XL = your_XL_application
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
AA2e72E said:
Excel has several events; I use the one that I have referred to earlier, SheetSelectionChange.
I want to be able to say:
xl.SheetSelectionChange = "Newx" i.e set the
SheetSelectionChange event to run the sub "Newx"; it should be
trigerred when I execute xl.Cells(1,2).Select i.e change the
selection.
Thsi is a trivial example: the principal should apply to more
useful Excel events, such as BeforeClose etc.