When AddIn Unchecked Delete It's Tools Menu Item How?

D

Dennis

I have an Add-In xla that has created a menu Item on the Tools Menu with the
following code in the xla project.

Private Sub Workbook_Open()
.......
Set NewItem = Application.CommandBars(1) _
.Controls("tools").Controls.Add
NewItem.Caption = MenuItemName
NewItem.OnAction = MenuItemMacro
NewItem.BeginGroup = True
.....
end sub

If the Add-In is subsequently unchecked in Tools->Add-Ins

How do I delete the menu Item from the Tools Menu? Just unchecking just left
the menu item on the tools menu creating an error when clicked.

If Tried

Private Sub Workbook_Close()
Application.CommandBars(1) _
.Controls("Tools").Controls(MenuItemName).Delete
End Sub

but this didn't work.
 
C

Celtic_Avenger

try by putting the same VBA in the before close action in the mai
Workbook code.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars(1) _
.Controls("Tools").Controls(MenuItemName).Delete
End Su
 
D

Dennis

Nevermind I found the solution on Google Groups.

In the "ThisWorkbook" of the xla I should use:

Private Sub Workbook_BeginsClose()
Application.CommandBars(1) _
.Controls("Tools").Controls(MenuItemName).Delete
End Sub

This will take the Tools menu item that I created off the Tools menu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top