Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default new menu opens in all worksheets

Using the following code, I fiind that the new menu appears in every
excel worksheet that is opened instead of appearing only in the
worksheet it belongs to. I've placed the code in the "ThisWorkbook"
module.
What can I do about this? I'd like this menu to appear only in it's
own worksheet.
Thanks in advance.
-----------

Private Sub Workbook_Open()
Dim cmbBar As CommandBar
Dim cmbControl As CommandBarControl

Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup,
temporary:=True) 'adds a menu item to the Menu Bar
With cmbControl
.Caption = "&NEW MENU" 'name of the menu
With .Controls.Add(Type:=msoControlButton)
.Caption = "Calculation1"
.OnAction = "Macro1"
End With
With .Controls.Add(Type:=msoControlButton) 'adds a
dropdown button to the menu item
.Caption = "Tables"
.OnAction = "Macro2"
End With
With .Controls.Add(Type:=msoControlButton) 'adds a
dropdown button to the menu item
.Caption = "Create New Sheet"
.OnAction = "Macro3"
End With

End With

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case the menu item has already been
deleted
Application.CommandBars("Worksheet Menu Bar").Controls("NEW
MENU").Delete 'delete the menu item
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default new menu opens in all worksheets

Put the code in the Worksheet_Activate and Worksheet_Deactivate events.

Mike F
"dolphin" wrote in message
...
Using the following code, I fiind that the new menu appears in every
excel worksheet that is opened instead of appearing only in the
worksheet it belongs to. I've placed the code in the "ThisWorkbook"
module.
What can I do about this? I'd like this menu to appear only in it's
own worksheet.
Thanks in advance.
-----------

Private Sub Workbook_Open()
Dim cmbBar As CommandBar
Dim cmbControl As CommandBarControl

Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup,
temporary:=True) 'adds a menu item to the Menu Bar
With cmbControl
.Caption = "&NEW MENU" 'name of the menu
With .Controls.Add(Type:=msoControlButton)
.Caption = "Calculation1"
.OnAction = "Macro1"
End With
With .Controls.Add(Type:=msoControlButton) 'adds a
dropdown button to the menu item
.Caption = "Tables"
.OnAction = "Macro2"
End With
With .Controls.Add(Type:=msoControlButton) 'adds a
dropdown button to the menu item
.Caption = "Create New Sheet"
.OnAction = "Macro3"
End With

End With

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case the menu item has already been
deleted
Application.CommandBars("Worksheet Menu Bar").Controls("NEW
MENU").Delete 'delete the menu item
End Sub






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
Excel opens two worksheets instead of one pspannuth Excel Discussion (Misc queries) 0 February 4th 10 03:12 PM
Alt E no longer opens Edit menu simonc Excel Discussion (Misc queries) 4 September 8th 08 03:52 PM
Alt+E No Longer Opens Edit menu dee Excel Discussion (Misc queries) 5 July 19th 07 01:08 AM
Excel file opens but no worksheets visible SELIGMAN MAINE Excel Discussion (Misc queries) 3 July 5th 06 10:32 PM
add a menu bar when document opens Todd[_5_] Excel Programming 5 September 10th 03 08:23 AM


All times are GMT +1. The time now is 04:55 AM.

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

About Us

"It's about Microsoft Excel"