In my add-in, trying to uninstall a command button that gets added in the Workbook_Open procedure doesn't want to work. In researching this, i found the following but don't understand it, but perhaps somebody could explain what it means and if this could explain why deleting the command button isn't working in the add-in (i even tried adding a simple MsgBox to the BeforeClose procedure and it didn't work, so apparently the add-in never gets to the BeforeClose event). Here's the info i found and don't understand:
Unlike sheet events, embedded charts and the Application object don't have events enabled by default. Before you can use events with an embedded chart or with the Application object, you must create a new class module and declare an object of type Chart or Application with events. You use the Class Module command (Insert menu) in the Visual Basic Editor to create a new class module.
To enable the events of the Application object, you'd add the following declaration to the class module.
Public WithEvents App As Application
After the new object has been declared with events, it appears in the Object box in the class module, and you can write event procedures for the new object. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure box.)
Before the procedures will run, however, you must connect the declared object in the class module to the Application object. You can do this from any module by using the following declaration (where "EventClass" is the name of the class module you created to enable events).
Public X As New EventClass
After you've created the X object variable (an instance of the EventClass class), you can set the App object of the EventClass class equal to the Microsoft Excel Application object.
Sub InitializeApp()
Set X.App = Application
End Sub
After you run the InitializeApp procedure, the App object in the EventClass class module points to the Microsoft Excel Application object, and the event procedures in the class module will run whenever the events occur.
Any insight?
Unlike sheet events, embedded charts and the Application object don't have events enabled by default. Before you can use events with an embedded chart or with the Application object, you must create a new class module and declare an object of type Chart or Application with events. You use the Class Module command (Insert menu) in the Visual Basic Editor to create a new class module.
To enable the events of the Application object, you'd add the following declaration to the class module.
Public WithEvents App As Application
After the new object has been declared with events, it appears in the Object box in the class module, and you can write event procedures for the new object. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure box.)
Before the procedures will run, however, you must connect the declared object in the class module to the Application object. You can do this from any module by using the following declaration (where "EventClass" is the name of the class module you created to enable events).
Public X As New EventClass
After you've created the X object variable (an instance of the EventClass class), you can set the App object of the EventClass class equal to the Microsoft Excel Application object.
Sub InitializeApp()
Set X.App = Application
End Sub
After you run the InitializeApp procedure, the App object in the EventClass class module points to the Microsoft Excel Application object, and the event procedures in the class module will run whenever the events occur.
Any insight?