ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   menu bars (https://www.excelbanter.com/excel-programming/297754-menu-bars.html)

majikman[_5_]

menu bars
 
i've created a menu on my toolbar of type Worksheet Menu Bar. Now,
want to use the same exact menu bars and I understand that I need t
use of type Chart Menu Bar. However, my menu bar has somewhere aroun
15 options and thus you can imagine that there is quite a bit of code
I don't want to have to copy and paste the same exact code to use fo
my chart menu bar. Is it possible to combine the code definition of th
menu bar to work in both types of menu bars? Thanks in advance

--
Message posted from http://www.ExcelForum.com


Melanie Breden

menu bars
 
i've created a menu on my toolbar of type Worksheet Menu Bar. Now, I
want to use the same exact menu bars and I understand that I need to
use of type Chart Menu Bar. However, my menu bar has somewhere around
15 options and thus you can imagine that there is quite a bit of code.
I don't want to have to copy and paste the same exact code to use for
my chart menu bar. Is it possible to combine the code definition of the
menu bar to work in both types of menu bars? Thanks in advance.


you can use the index of the Commandbars for both menubars:

Sub MyMenu()
Dim intI As Integer

For intI = 1 To 2
On Error Resume Next
Application.CommandBars(intI).Controls("My Button").Delete
On Error GoTo 0

With Application.CommandBars(intI).Controls.Add(Tempora ry:=True)
.Style = msoButtonCaption
.Caption = "My Button"
.OnAction = "MyMakro"
End With
Next intI
End Sub

Sub MyMakro()
MsgBox "Hello world"
End Sub

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



All times are GMT +1. The time now is 12:38 PM.

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