Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding & removing menu buttons

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding buttons to a new menu bar Greegan Excel Worksheet Functions 1 April 7th 06 07:55 AM
Adding a menu item right click menu when clicking on a single. Andoni[_28_] Excel Programming 0 September 2nd 04 10:23 PM
Removing Addin Buttons on Toolbars Dan Grindstaff Excel Programming 3 February 17th 04 04:31 PM
Adding menu to the mouse right click pop-up menu Jack Excel Programming 1 February 12th 04 05:23 AM
Adding and Removing Custom Menu Items for one file... Jon Kane Excel Programming 2 September 17th 03 07:23 PM


All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"