View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Commandbar on thisworkbook only

The answer is yes. However, if you search this discussion for "GB Toolbar"
you will see a thread that has 28+ messages. Look towards the end of the
thread for a more up-to-date version of the code. You should be able to snip
out the Tool_Bar_Delete (Or similiarly named) section to perform what you
want. You will also need to add some code to the ThisWorkbook_Close section
to force destruction of the toolbar.

The "final" version posted there (by me) allows for multiple toolbars to be
created, one or more for each worksheet, or of course none to be present on a
worksheet. There is an upper programmed limit of 10, but by removing one and
inserting another that upper limit could be "exceeded." (I have not
implemented this option in my code yet however.)


"Rene Petersen" wrote:

When creating a commandbar with the code below it is only a temporarily
commandbar and that is great, however it is only temp in that sense that you
have to close the Excel application down and reopen before the commandbar
removed.

Is there away to have the commandbar removed as soon as you close the
worksheet that has the macro and command?


Dim oCb As CommandBar
Dim oCtl As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtl.Caption = "myButton"
oCtl.Style = msoButtonCaption
oCtl.OnAction = "myMacro"
End With


Thank you in advance for you help.

Rene