Consulting

Results 1 to 4 of 4

Thread: toolbar mishap

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    toolbar mishap

    hello all
    i have vba code for a toolbar . i place it's name in workbook open event.
    i keep getting an error message.
    why?
    the code:
    [VBA]
    Sub cmd()
    Dim newbtn As CommandBarButton
    Application.CommandBars.Add ("johnske")
    With CommandBars("johnske")
    .Position = msoBarTop
    .Visible = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 375
    .OnAction = "vin1"
    .Caption = "filter data"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 469
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    .BeginGroup = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 396
    .OnAction = "daphnebook"
    .Caption = "vbaexpress"
    .BeginGroup = True
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End Sub

    [/VBA]
    thanks
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Haven't we been here before?

    [vba]
    Sub cmd()
    Dim oCB As CommandBar
    Dim newbtn As CommandBarButton
    Set oCB = Application.CommandBars.Add(Name:="johnske", temporary:=True)
    With oCB
    .Position = msoBarTop
    .Visible = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 375
    .OnAction = "vin1"
    .Caption = "filter data"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 469
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    .BeginGroup = True
    End With
    Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 396
    .OnAction = "daphnebook"
    .Caption = "vbaexpress"
    .BeginGroup = True
    End With

    End Sub
    [/vba]

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    What is the error and where does it occur?

    Runs OK for me (WinXP/XL2003)

    I think you might want to close your with block for each newbtn though... as posted above
    K :-)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Killian
    What is the error and where does it occur?

    Runs OK for me (WinXP/XL2003)

    I think you might want to close your with block for each newbtn though... as posted above
    The Commandbars failed on XP for me, I had to add Application.

Posting Permissions

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