ObjCommand BarButtonOnAction StepByStep Summary for COM AddIn Command Bars

To create an Explorer command bar button in an Outlook COM Add-in

1. In the Add-In Designer's module or the class module for the base class, use the WithEvents keyword to declare a module-level variable of type CommandBarButton. This creates an event-ready CommandBarButton object.

2. In the same module, create the Click event procedure stub for the CommandBarButton object by clicking the name of the object variable in the Object box and then clicking Click in the Procedure box.

3. Write code within the event procedure stub.

4. In the OnConnection event procedure or in the InitHandler procedure for your base class, check to see whether the command bar control already exists, and return a reference to it if it does. If it doesn't exist, create the new command bar control and return a reference to it. You need to check whether the command bar control exists so that you don't create a new control each time your code runs.

5. When you create the new command bar control, set the Tag property for the CommandBarButton object to a unique string. The Tag property lets you easily find the control using the FindControl method.

6. When you create the new command bar control, set the OnAction property for the command bar control if the COM Add-in is to be demand-loaded. If you fail to set the OnAction property, the command bar button will load the Add-in the first time Outlook starts, but will not load the Add-in when Outlook is closed and re-opened.

7. Within the OnConnection event procedure or in the InitHandler procedure for your base class, assign the reference to the command bar control to the event-ready CommandBarButton object variable.

8. Add code to the OnDisconnection event or to the UnlnitHandler procedure in the base class to remove the command bar control when the Add-in is unloaded.

0 0

Post a comment