Cuối cùng, khi bạn đã sẵn sàng để gỡ lỗi, bạn có thể làm theo các thủ tục như những người sử dụng để gỡ lỗi một NET add-in trong Visual Studio Đặt breakpoint trong các add-in (như trong các chức năng OnConnection) và sau đó chạy trong chế độ Debug. Nhưng thay vì Visual NET Studio, Excel sẽ khởi động | Writing .NET Add-ins for Microsoft Office 303 Figure Use the Standard toolbar to quickly switch configurations. Finally when you are ready to debug you can follow the same procedures as those used to debug an add-in in Visual Studio .NET. Set your breakpoints in the add-in such as in the OnConnection function and then run in Debug mode. But instead of Visual Studio .NET Excel will start up. Responding to Office Events The Office objects include several events to which your code can respond. For example the object includes an event called WorkbookOpen which occurs when the Excel user opens a workbook or when an automation program causes Excel to open a workbook. The application object of each Office application includes several events as do many of the other objects within the application. For example the object includes events such as NewWorkbook SheetActivate SheetBeforeDou-bleClick SheetBeforeRightClick and SheetCalculate whose names are self-explanatory. You can find out all the events by starting the Office application for which you re writing the add-in then opening the application s Visual Basic for Applications VBA IDE by choosing Tools1 -Macro1 z Visual Basic Editor. Inside the VBA IDE choose Microsoft Visual Basic Help. Inside the online help is a reference for all the objects and their events. Before you can properly respond to events make sure the interop assemblies are correct. Before trying out this example refer to the sidebar Important Fixing Excel and Outlook. 304 Chapter 13 To respond to an event you need to create a delegate object which in the case of a static function is really the address of a function or in the case of a member function the address of a function and an object instance. You then assign the delegate object to the event object. First I show you an example in followed by the same example in C Dim excelevent As excelevent New Excel. _ .