Consulting

Results 1 to 6 of 6

Thread: toolbar do not show

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

    toolbar do not show

    hell
    i built a custom toolbar .i have assinged a macro to each contol.
    why don't i see all the controls & faceid's.i named it johnske in honor of John Skewes a great teacher who taught me a lot.
    thanks
    [VBA]
    Dim newbtn As CommandBarButton
    With Application.CommandBars
    .Add("johnske").Visible = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 333
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End Sub

    [/VBA]
    moshe

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    I've copied the code and ran it.
    Yep, creates a toolbar named johnske.
    It shows 8 buttons on the toolbar.
    What happens on your system?.

    I've noticed you missed the Sub name on first line.
    Also if you've already created the toolbar before
    and it's not showing, you need to delete the toolbar
    before running the code or you get:
    'Invalid procedure call or argument'
    error message.

    [VBA]
    Sub johnskeToolbar()
    Dim newbtn As CommandBarButton
    On Error Resume Next
    'Delete toolbar if exists
    Application.CommandBars("johnske").Delete
    With Application.CommandBars
    .Add("johnske").Visible = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 333
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End With
    End Sub
    [/VBA]


    What happens when you run the code?.
    Any error messages?.

    Marcster.
    Last edited by Marcster; 12-29-2005 at 03:35 AM. Reason: Spelling mistake

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Here's an add-in which lets you see all the
    face-id's and numbers you can use in Excel:

    http://j-walk.com/ss/excel/tips/tip67.htm

    Marcster.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Works fine for me.

    BTW, you don't need the multiple layered indenting, it does actually make it harder to read

    [vba]
    Dim newbtn As CommandBarButton
    With Application.CommandBars
    .Add("johnske").Visible = True
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 333
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    End With
    Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
    With newbtn
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    End With
    End With
    [/vba]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can simplify it more with no Set

    [vba]
    Dim newbtn As CommandBarButton
    With Application.CommandBars
    .Add("johnske").Visible = True
    With CommandBars("johnske")
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 325
    .OnAction = "findafile"
    .Caption = "open a file"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 333
    .OnAction = "sortworksheets"
    .Caption = "sort ws"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 353
    .OnAction = "lookfor_demo2"
    .Caption = "partial text"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 383
    .OnAction = "nnnn"
    .Caption = "update comments"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 384
    .OnAction = "rowme3"
    .Caption = "shade altenate rows"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 395
    .OnAction = "horin"
    .Caption = "accounting format"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 386
    .OnAction = "finders44"
    .Caption = "find text"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .FaceId = 387
    .OnAction = "closeallbut"
    .Caption = "closeallbut"
    End With
    End With
    End With
    [/vba]

  6. #6
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by lior03
    hell
    i built a custom toolbar .i have assinged a macro to each contol.
    why don't i see all the controls & faceid's.i named it johnske in honor of John Skewes a great teacher who taught me a lot.
    thanks...
    Thanx moshe, that's very flattering.

    As Bob said in his last post, it's better without all the "Sets", and as he said previous to that, keep all the "Withs" and "End Withs" together so you can keep track of what "With" belongs with each "End With".

    Happy New Year,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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