Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

new menu opens in all worksheets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dolphin - 30 May 2008 11:46 GMT
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
Mike Fogleman - 30 May 2008 13:00 GMT
Put the code in the Worksheet_Activate and Worksheet_Deactivate events.

Mike F
> Using the following code, I fiind that the new menu appears in every
> excel worksheet that is opened instead of appearing only in the
[quoted text clipped - 39 lines]
> MENU").Delete 'delete the menu item
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.