|
5.9. Respond to Excel Events in .NETResponding to Excel events in .NET code is done much the same way as in VBA with one difference: in .NET, event procedures are associated with objects using the Handles clause. Excel uses the procedure name to associate an event with an object. The .NET approach means that a single procedure can handle multiple events. 5.9.1. How to do itTo respond to Excel events in .NET:
For example, the following code sorts any string entered in cell A2 and displays the result in B2. It may look familiar, since it uses the NetString class created earlier to perform the sort. Private Sub m_wb_SheetChange(ByVal Sh As Object, _ ByVal Target As Microsoft.Office.Interop.Excel.Range) _ Handles m_wb.SheetChange If Target.Address = "$A$2" Then Dim NetStr As New NetForExcel.NetString m_wb.Worksheets(1).Range("B2").Value = NetStr.Sort(Target.Value) End If End Sub |
|