+ Reply to Thread
Results 1 to 2 of 2

how to create sub menu items in Excel?

  1. #1
    Joshua
    Guest

    how to create sub menu items in Excel?

    Hi all,
    I created a custom menu in Excel. I would like to create sub menu items for
    one of the menu items. I get an error 'Object not supported by this method'.

    I have copied the code below: any suggestions why the error pops up?

    Thanks in advance for any pointers.

    the code:

    Private Sub Workbook_Open()

    Dim obj As Object
    Dim helpmenu As Object
    Dim btnobj As Object
    Dim SubMenuItem As Object

    For Each obj In Application.CommandBars(1).Controls
    If obj.Caption = "De&mo Tool" Then
    obj.Delete
    Exit For
    End If
    Next
    Set obj = Application.CommandBars(1).Controls.Add(msoControlPopup)
    obj.Caption = "De&mo Tool"

    Set btnobj = obj.Controls.Add(msoControlButton)
    btnobj.Caption = "&Save data to file"
    btnobj.OnAction = ThisWorkbook.Name & "!store"
    btnobj.FaceId = 600
    Set btnobj = obj.Controls.Add(msoControlButton)
    btnobj.Caption = "F&ilter"
    btnobj.FaceId = 601
    Set SubMenuItem = btnobj.Controls.Add(Type:=msoControlButton)
    SubMenuItem.Caption = "&Asia"
    SubMenuItem.OnAction = "Macrofilterasia"
    End Sub

    With regards,
    Josh

  2. #2
    Tom Ogilvy
    Guest

    Re: how to create sub menu items in Excel?

    You can't add a button to a button which is what you are trying to do.

    Set btnobj = obj.Controls.Add(msoControlButton)
    should probably be msoControlPopup

    --
    Regards,
    Tom Ogilvy


    "Joshua" <[email protected]> wrote in message
    news:[email protected]...
    > Hi all,
    > I created a custom menu in Excel. I would like to create sub menu items

    for
    > one of the menu items. I get an error 'Object not supported by this

    method'.
    >
    > I have copied the code below: any suggestions why the error pops up?
    >
    > Thanks in advance for any pointers.
    >
    > the code:
    >
    > Private Sub Workbook_Open()
    >
    > Dim obj As Object
    > Dim helpmenu As Object
    > Dim btnobj As Object
    > Dim SubMenuItem As Object
    >
    > For Each obj In Application.CommandBars(1).Controls
    > If obj.Caption = "De&mo Tool" Then
    > obj.Delete
    > Exit For
    > End If
    > Next
    > Set obj = Application.CommandBars(1).Controls.Add(msoControlPopup)
    > obj.Caption = "De&mo Tool"
    >
    > Set btnobj = obj.Controls.Add(msoControlButton)
    > btnobj.Caption = "&Save data to file"
    > btnobj.OnAction = ThisWorkbook.Name & "!store"
    > btnobj.FaceId = 600
    > Set btnobj = obj.Controls.Add(msoControlButton)
    > btnobj.Caption = "F&ilter"
    > btnobj.FaceId = 601
    > Set SubMenuItem = btnobj.Controls.Add(Type:=msoControlButton)
    > SubMenuItem.Caption = "&Asia"
    > SubMenuItem.OnAction = "Macrofilterasia"
    > End Sub
    >
    > With regards,
    > Josh




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1