Consulting

Results 1 to 6 of 6

Thread: Grey out menu item

  1. #1
    VBAX Newbie
    Joined
    May 2009
    Posts
    3
    Location

    Grey out menu item

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    May 2009
    Posts
    3
    Location
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well I tried it before posting and it greyed it out, as this image shows
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Newbie
    Joined
    May 2009
    Posts
    3
    Location
    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

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •