Microsoft Office Tutorials and References
In Depth Information
Example 10-3. The DeleteCustomMenuItem Procedure
' Set tag property to find it later for deletion
cbcpop.Tag = "SRXUtilsCustomMenu"
' Add menu item to popup menu
With cbcpop.Controls.Add(Type:=msoControlButton, _
.Caption = "&ActivateSheet"
.OnAction = "ActivateSheet"
End With
End Sub
Also place the DeleteCustomMenuItem procedure shown in Example 10-3 into basMenus :
Example 10-3. The DeleteCustomMenuItem Procedure
Sub DeleteCustomMenuItem()
Dim cbc As CommandBarControl
Set cbc = Application.CommandBars( _
"Worksheet menu bar"). _
FindControl(Type:=msoControlPopup, _
If Not cbc Is Nothing Then cbc.Delete
End Sub
10.3.3 Implementing the Features of the Add-In
Since the ActivateSheet utility (which is invoked when the user selects the ActivateSheet
custom menu item created by the code in Example 10-2 ) is very simple, it does not require its own
code module. We simply add the following procedure to the basMain code module, which we
also must create:
Public Sub ActivateSheet()
MsgBox "This is the ActivateSheet utility"
End Sub
10.3.4 Final Steps
Finally, you should follow these steps:
Compile the project. Use the Debug menu to compile the SRXUtils.xls project.
Set the properties. Set the workbook and project properties as shown in Figure 10-6 a nd
Figure 10-8 , making any necessary changes based on the name you have chosen for your
Protect the add-in. Under the Protection tab of the project's Properties dialog, check the
"Lock project for viewing" checkbox and enter a password.
Save the add-in. Save the project as an add-in named SRXUtils.xla in a directory of your
Now we are ready to try the add-in. Close the SRXUtils.xls workbook and open a new workbook.
Select the Add-Ins menu item under the Tools menu and hit the Browse button on the Add-Ins
dialog. Locate your SRXUtils.xla file. Then check the entry in the Add-Ins dialog. You should see
the new Custom menu in the worksheet menu bar. Select the ActivateSheet item. You should get
the expected message box. Finis .
As mentioned earlier, as we progress through the topic, we will make this example add-in much
more meaningful.
Search JabSto ::

Custom Search