Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Custom MenuBar buttons (vb6.0 xl2000)

    From VB I've created an instance of Excel (CreateObject); set xl as this obj var; and created a new MenuBar and added 4 buttons: Print, Undo, Redo, and Zoom.
    The Print and Zoom buttons operate correctly (their Action works); but, not the Undo or Redo. The problem lies, I believe, in assigning an ID to these buttons ( which, as I understand it, also assigns an "on action" for builtin buttons).
    When I ran a procedure to genarate the ids and faceids for all builtin buttons I came up with all the buttons having the same id #s as faceid #s However, when I insert and id for Undo and Redo I get an error.

    Any Ideas on how to get the Action to work for my Undo and Redo buttons?


    Public Sub AddCustomMenuBar()
    'CREATE A Custom MENU BAR

    Dim cbs As Object
    Dim cb As Object
    Set cbs = xl.CommandBars

    'delete any old menu bar by this name
    On Error Resume Next
    Set cb = cbs("CustomMenuBar")
    cb.Delete

    'add new Menu Bar
    Set cb = cbs.Add("CustomMenuBar", 1, True, True)
    cb.Visible = True

    'add buttons

    'Print Button
    Dim btn1 As Object
    Set btn1 = cb.Controls.Add(1, _
    Temporary:=True, _
    Id:=4)
    btn1.OnAction = "PRINT_TABLE" 'MyProcedure

    'Undo Button
    Dim btn2 As Object
    Set btn2 = cb.Controls.Add(1, _
    Temporary:=True)
    btn2.FaceId = 128

    ' NOTE: If I add btn2.ID=128 , I get and error
    ' How can I assign the proper action to this button?

    'Redo Button
    Dim btn3 As Object 'CommandBarControl
    Set btn3 = cb.Controls _
    .Add(1, _
    Temporary:=True)
    btn3.FaceId = 129
    ' NOTE: If I add btn3.ID=129 , I get and error
    ' How can I assign the proper action to this button?


    'Zoom Button
    Dim btn4 As Object 'CommandBarControl
    Set btn4 = cb.Controls _
    .Add(1, _
    Id:=925, _
    Temporary:=True)

    End Sub

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Custom MenuBar buttons (vb6.0 xl2000)

    This does work for me:

    Option Explicit

    Public Sub AddCustomMenuBar()
    'CREATE A Custom MENU BAR

    Dim cbs As Object
    Dim cb As Object
    Set cbs = CommandBars

    'delete any old menu bar by this name
    On Error Resume Next
    Set cb = cbs("CustomMenuBar")
    cb.Delete

    'add new Menu Bar
    Set cb = cbs.Add("CustomMenuBar", 1, True, True)
    cb.Visible = True

    'add buttons

    'Print Button
    Dim btn1 As Object
    Set btn1 = cb.Controls.Add(1, _
    Temporary:=True, _
    ID:=4)
    btn1.OnAction = "PRINT_TABLE" 'MyProcedure

    'Undo Button
    Dim btn2 As Object
    Set btn2 = cb.Controls.Add(6, 128, _
    Temporary:=True)
    btn2.FaceId = 128

    ' NOTE: If I add btn2.ID=128 , I get and error
    ' How can I assign the proper action to this button?

    'Redo Button
    Dim btn3 As Object 'CommandBarControl
    Set btn3 = cb.Controls _
    .Add(6, 129, _
    Temporary:=True)
    btn3.FaceId = 129
    ' NOTE: If I add btn3.ID=129 , I get and error
    ' How can I assign the proper action to this button?


    'Zoom Button
    Dim btn4 As Object 'CommandBarControl
    Set btn4 = cb.Controls _
    .Add(1, _
    ID:=925, _
    Temporary:=True)

    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Custom MenuBar buttons (vb6.0 xl2000)

    I think your problem is the Un and Redo buttons are not type 1 (msoControlButton),
    but type 6 (msoControlSplitDropDown).

    Set btn2 = cb.Controls.Add(Type:=6, Id:=128,Temporary:=True)

    You don't need to mention FaceID if the button is built it. (unless of course, you
    don't want the default icon)
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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