ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problem with custom menu (https://www.excelbanter.com/excel-programming/328628-problem-custom-menu.html)

tony

problem with custom menu
 
I had to modify my custom menu. Originally adding and removing my custom
menus was done by the following code:

-------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = "My Macros"
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------
Sub RemoveMenus()
On Error Resume Next
' Remove Menu Bar.
CommandBars("Worksheet Menu Bar").Controls("My Macros").Delete
End Sub
----------------------------------------------------------


Because I have to use special characters in the names of my custom menu,
following the advice from this group I modified my code to:

----------------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = Range("menu1")
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------

Now executing of the code is replacing before last menu item with my menu.
What I am doing wrong ? How I have to modify my code so that my menu will add
new menu, not replace one of the existing ones. How I need to modify the
removing code so that my new menu will be removed when closing the workbook.

Thanks for advice.

Regards,

Tony


tony

problem with custom menu
 
I had a problem with uploading of my question. This is duplicated post.
Please ignore.

Tony

"Tony" wrote:

I had to modify my custom menu. Originally adding and removing my custom
menus was done by the following code:

-------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = "My Macros"
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------
Sub RemoveMenus()
On Error Resume Next
' Remove Menu Bar.
CommandBars("Worksheet Menu Bar").Controls("My Macros").Delete
End Sub
----------------------------------------------------------


Because I have to use special characters in the names of my custom menu,
following the advice from this group I modified my code to:

----------------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = Range("menu1")
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------

Now executing of the code is replacing before last menu item with my menu.
What I am doing wrong ? How I have to modify my code so that my menu will add
new menu, not replace one of the existing ones. How I need to modify the
removing code so that my new menu will be removed when closing the workbook.

Thanks for advice.

Regards,

Tony


Patrick Molloy[_2_]

problem with custom menu
 
Sub RemoveMenus()
On Error Resume Next
' Remove Menu Bar.
CommandBars("Worksheet Menu Bar").Controls(Range("menu1").Value).Delete
End Sub
Sub AddMenuBAr()
Dim cmbMenu As CommandBarControl
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = Range("menu1")
.DescriptionText = "Macros Menu"
End With
End Sub

"Tony" wrote:

I had to modify my custom menu. Originally adding and removing my custom
menus was done by the following code:

-------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = "My Macros"
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------
Sub RemoveMenus()
On Error Resume Next
' Remove Menu Bar.
CommandBars("Worksheet Menu Bar").Controls("My Macros").Delete
End Sub
----------------------------------------------------------


Because I have to use special characters in the names of my custom menu,
following the advice from this group I modified my code to:

----------------------------------------------------------
Set cmbMenu = CommandBars("Worksheet Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Befo=CommandBars("Worksheet Menu Bar") _
.Controls.Count)
' Set the caption of the new menu.
With cmbMenu
.Caption = Range("menu1")
.DescriptionText = "Macros Menu"
End With
----------------------------------------------------------

Now executing of the code is replacing before last menu item with my menu.
What I am doing wrong ? How I have to modify my code so that my menu will add
new menu, not replace one of the existing ones. How I need to modify the
removing code so that my new menu will be removed when closing the workbook.

Thanks for advice.

Regards,

Tony



All times are GMT +1. The time now is 01:40 AM.

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