Solved

How to Customize Excel menu bar at run time?

Posted on 2002-03-07
2
151 Views
Last Modified: 2010-05-02
Hello all
I need to add items to excel menu bar at runtime
and to load this menu as an Addin.

I prefer to see code that create a new menu item
(like file,edit,tools etc.) and add to it items
and sub menus with connection to event handlers

Thanks
0
Comment
Question by:avi9260
2 Comments
 
LVL 3

Accepted Solution

by:
nzjonboy earned 70 total points
ID: 6848900
check this out

Sub Auto_Open()
  Dim myBlankPop As CommandBarPopup
  Dim myBlankSubPop As CommandBarPopup
  Dim myBlankBtn As CommandBarButton

  Set myBlankPop = CommandBars("Worksheet Menu Bar").Controls.Add(msoControlPopup, , , 11, True)
 
  With myBlankPop
    .Caption = "Test"
 
    Set myBlankBtn = .Controls.Add(msoControlButton)
 
    With myBlankBtn
      .Style = msoButtonIconAndCaption
      .Caption = "Test Button"
      .FaceId = 480
      .OnAction = "clickBtn"
    End With
   
    Set myBlankBtn = Nothing
   
    Set myBlankSubPop = .Controls.Add(msoControlPopup)
   
    With myBlankSubPop
      .Caption = "Sub Menu"
      Set myBlankBtn = .Controls.Add(msoControlButton)
      With myBlankBtn
        .BeginGroup = True
        .Style = msoButtonIconAndCaption
        .Caption = "Test Button"
        .FaceId = 1845
        .OnAction = "clickSubBtn"
      End With
      Set myBlankBtn = Nothing
    End With
   
    Set myBlankSubPop = Nothing
       
  End With
End Sub

Function clickBtn()
  MsgBox "click"
End Function

Function clickSubBtn()
  MsgBox "click from sub menu"
End Function


hope this helps

nzjonboy
0
 

Author Comment

by:avi9260
ID: 6849932
Thanks a lot
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question