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

Actually, this option would remove the button, but not the commandbar.
Obviously to remove the commandbar, just remove from the below code the
..Controls("myButton") portion, and the commandbar will be deleted. it will
error if the user has also deleted it from the View-Toolbars section, so
might want some error controls. Just a thought.

"Bob Phillips" wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Worksheet Menu Bar") _
.Controls("myButton").Delete
End Sub


'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Rene Petersen" wrote in message
...
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