Solved

How to Customize Excel menu bar at run time?

Posted on 2002-03-07
2
149 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
Comment Utility
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
Comment Utility
Thanks a lot
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now