PDA

View Full Version : Grey out menu item



Peter100
05-11-2009, 03:32 AM
Hi

I have an addin menu based on the following code and want the menu 2 option visible but grey, is this possible

Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&New Menu").Delete
On Error GoTo 0

Set cbMainMenuBar = _
Application.CommandBars("Worksheet Menu Bar")

iHelpMenu = _
cbMainMenuBar.Controls("Help").Index


Set cbcCutomMenu = _
cbMainMenuBar.Controls.Add(Type:=msoControlPopup, _
Before:=iHelpMenu)

'
cbcCutomMenu.Caption = "&New Menu"


With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Menu 1"
.OnAction = "MyMacro1"
End With

With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Menu 2"
.OnAction = "MyMacro2"
End With


End Sub

Bob Phillips
05-11-2009, 04:05 AM
I have already showed you how to do this at your posting in MrExcel http://www.mrexcel.com/forum/showthread.php?t=389378

Do not cross-post. Cross-posters deserve to be banished to the deepest recesses of the internet.

Peter100
05-11-2009, 04:12 AM
Hi Xld

As you saw in my reply, I couldn't get it to work and as you didn't respond further I tried this forum. No cross listing was intended.

I appreciate your reply might well work but as a fairly newcomer to VBA my knowledge is extremely limited and needed further assistance.

Bob Phillips
05-11-2009, 04:28 AM
Well I tried it before posting and it greyed it out, as this image shows

Peter100
05-11-2009, 04:38 AM
Could you please show me how it fits into my code as I cant make it happen and as I said I am quite green at VBA

Thanks

Peter

Bob Phillips
05-11-2009, 06:49 AM
Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&New Menu").Delete
On Error GoTo 0

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")

iHelpMenu = cbMainMenuBar.Controls("Help").Index

Set cbcCutomMenu = _
cbMainMenuBar.Controls.Add(Type:=msoControlPopup, _
Before:=iHelpMenu)

With cbcCutomMenu

.Caption = "&New Menu"

With .Controls.Add(Type:=msoControlButton)

.Caption = "Menu 1"
.OnAction = "MyMacro1"
End With

With .Controls.Add(Type:=msoControlButton)

.Caption = "Menu 2"
.OnAction = "MyMacro2"
.Enabled = False '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
End With
End With

End Sub