+ Reply to Thread
Results 1 to 2 of 2

Put a custom image in a CommandBar Control?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Put a custom image in a CommandBar Control?

    I have a 16x16 image that I want to use for a context sensitive menu item I created. When a user right-clicks on a cell, the Cell CommandBar menu displays and my custom addition is at the bottom. I would like to put my own custom image in there instead of using a stock FaceId value. How do I do this? Can I have the image saved within the workbook (in a xlVeryHidden sheet) instead of having to load it? For example, I don't want :
    .Picture = LoadPicture("C:\adidas_commandbar1.JPG")
    I'd rather do something along the lines of (I want to reference the image from within the workbook):
    .Picture = Sheets("Reference").Pictures("Picture 1")
    Here's my code so far and it works:
    Dim cbItem As CommandBarControl
        Set cbItem = Application.CommandBars("Cell").Controls.Add  'Add new menu item
        With cbItem
            .BeginGroup = True  'Add separator bar
    '        .FaceId = 2138  ' I don't want to use this method!
            .Picture = LoadPicture("C:\adidas_commandbar1.JPG")
            .Caption = "Transfer Data to Master Sheet"  'Menu item caption (what the user sees on the menu
            .OnAction = "'" & ThisWorkbook.Name & "'!PullData"  'Run this macro if selected
        End With
    ~Toby

  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello,

    You could stock your custom picture in an ImageList control an call it in your CommandBar:

    .Picture = Feuil1.ImageList1.ListImages(1).Picture

    Private Sub Workbook_Open()
        Dim CmdBar As CommandBar
        Dim Bouton As CommandBarButton
        
        Set CmdBar = Application.CommandBars _
            .Add(Name:="MaBarrePerso", Position:=msoBarTop, Temporary:=True)
        
        Set Bouton = CmdBar.Controls.Add(Type:=msoControlButton)
        With Bouton
            .Picture = Feuil1.ImageList1.ListImages(1).Picture
            .OnAction = "Macro1"
        End With
        
        CmdBar.Visible = True
    End Sub


    Regards
    michel
    Last edited by michelxld; 03-15-2008 at 01:47 PM.

+ 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