Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is a delete version that will work in Excel 97 which does not have
FindControls (may or may not be an issue) Sub Tester2A() Dim Ctrl As Office.CommandBarControl Set Ctrl = Application.CommandBars. _ FindControl(Tag:="your tag value") Do While Not Ctrl Is Nothing Ctrl.Delete Set Ctrl = Application.CommandBars. _ FindControl(Tag:="your tag value") Loop End Sub Should work in later versions as well. -- Regards, Tom Ogilvy "Chip Pearson" wrote in message ... Put a unique value in the Tag property of the control when you create it, and then use FindControls with the Tag value to find and delete your controls. E.g., To create, With CommandBars("Worksheet Menu Bar").Controls.Add .Caption = "Box Units" .Style = msoButtonCaption .OnAction = "NameBoxes" .Tag = "your tag value" End With And, to delete, Dim Ctrl As Office.CommandBarControl For Each Ctrl In Application.CommandBars. _ FindControls(Tag:="your tag value") Ctrl.Delete Next Ctrl -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "R. Choate" wrote in message ... I have code in my "This Workbook" module to add 2 buttons to the menu bar. Here is the current code for that: With CommandBars("Worksheet Menu Bar").Controls.Add .Caption = "Box Units" .Style = msoButtonCaption .OnAction = "NameBoxes" End With With CommandBars("Worksheet Menu Bar").Controls.Add .Caption = "Clear Sheets" .Style = msoButtonCaption .OnAction = "ClearAll" End With I need to replace this with better code AND add code to my BeforeClose event to delete the buttons. The kicker is that there might be several copies of each button if the user has opened more than one copy of the file or has opened it multiple times. I need to have the code delete all possible instances (copies) of each of these 2 buttons. Any good ideas? -- RMC,CPA |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding buttons to a new menu bar | Excel Worksheet Functions | |||
Adding a menu item right click menu when clicking on a single. | Excel Programming | |||
Removing Addin Buttons on Toolbars | Excel Programming | |||
Adding menu to the mouse right click pop-up menu | Excel Programming | |||
Adding and Removing Custom Menu Items for one file... | Excel Programming |