Results 1 to 12 of 12

Thread: Adding icons to custom commandbar menus

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    So the key parts of the code are

    Sub test()
    Dim cmbTargetMenuBar As CommandBar
    Dim cbbNewMenuItem As CommandBarButton
    Set cmbTargetMenuBar = CommandBars.Add
    With cmbTargetMenuBar
        .Visible = True
        Set cbbNewMenuItem = .Controls.Add(msoControlButton, , , , False)
        With cbbNewMenuItem
            .Caption = "Test caption"
            .OnAction = "testroutine"
            .Style = msoButtonIconAndCaption
            Sheets(1).Shapes("testicon").Copy
            .PasteFace
        End With
    End With
    End Sub
    So with a picture named "testicon" on sheet 1, I get a bar/button/icon.

    You'll get a "Method... failed" error if:
    there's nothing on the clipboard
    the clipboard contents isn't compatible

    Although, using similar code, I had this error occasionally (actually rare and randomly) when running from Excel97 - I could never replicate it under test conditions and since the project spec specified 2000+, I didn't chase it down.
    Last edited by Aussiebear; 04-26-2023 at 07:14 PM. Reason: Adjusting the code tags
    K :-)

Posting Permissions

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