ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to add entries in the Menue bar with VBA code? (https://www.excelbanter.com/excel-programming/381963-how-add-entries-menue-bar-vba-code.html)

Chip Pearson

How to add entries in the Menue bar with VBA code?
 
Try some code like the following:

Sub CreateMenuAndItem()

Dim MenuBar As Office.CommandBar
Dim TopMenu As Office.CommandBarPopup
Dim MenuItem As Office.CommandBarButton

Set MenuBar = Application.CommandBars.FindControl(ID:=30007).Par ent
Set TopMenu = MenuBar.Controls.Add(Type:=msoControlPopup, temporary:=True)
TopMenu.Caption = "&My Menu"
Set MenuItem = TopMenu.Controls.Add(Type:=msoControlButton, temporary:=True)
With MenuItem
.Caption = "&Click Me"
.Style = msoButtonCaption
.OnAction = "'" & ThisWorkbook.Name & "'!MacroName"
.Tag = "SOME_TEXT_VALUE_FOR_YOUR_APP"
End With

End Sub

Sub MacroName()
MsgBox "Hello World"
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)

"Marcel Marien" wrote in message
...
Hello,

can anybody tell me how to add a new entry into the main menue bar from
inside a macro? I tried to use the macro recorder, but it seems that this
kind of operation can not be recorded.

Marcel




Marcel Marien

How to add entries in the Menue bar with VBA code?
 
Hello,

can anybody tell me how to add a new entry into the main menue bar from
inside a macro? I tried to use the macro recorder, but it seems that this
kind of operation can not be recorded.

Marcel




All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com