Consulting

Results 1 to 5 of 5

Thread: Sleeper: Custom Icons in Excel

  1. #1
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location

    Sleeper: Custom Icons in Excel

    I have probably gotten this answer before, but cannot remember.
    I have a Custom Commandbar for gathering earthquake data on the web - there are submenu items for gathering, formatting, etc and everything works great.

    What I want to do is get 'custom' icons onto the dropdown context menu. Not icons that were modified from inherent images in MS Office (such as the Customize > Custom Button > then right-clicking the smilie button to Edit it); I have icons that were created in an icon making software that I would like to use for the submenu items,
    Mmm...is this possible? I have cruised the Newsgroups and some general searching on Google but haven't found the answer to this specific use of 'outsourced' icons for an Excel App.

    I want to use the custom icons in the Excel app - don't care how I need to do it really but I could use some help now.

    **Since I will be sending this app to at least two other people, I need the icons to go with the Application (which means that they will need to be stored in the same directory as the XLS, correct?)**

    Thanks for having a look!

    Scott
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    If you can copy it to the clipboard you can .PasteFace but it HAS to be the correct size. The way I do it in VB is to Clipboard.SetData LoadResPicture(101, vbResBitmap) then .PasteFace. The only other way (I haven't tested just a guess) is to put the icon in a cell, copy it to the clipboard, and paste back to the button.

    Hmmmmm umm I could write a dll/exe that would accept a location(full path) to the icon, load it in the clipboard, and let you handle it from there? maybe?

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I got it to work with this:

    The below is a sample, this not the full code or sub or function.

    If MyButton Is Nothing Then
    Set MyButton = Application.CommandBars(TOOLBAR_NAME).Controls.Add(1)
    End If
    With MyButton
    .Caption = "Enter Data"
    .Style = msoButtonIconAndCaption 'icon and caption 
    '.Style = msoButtonCaption 'caption only
    '.Style = msoButtonIcon 'icon only
    .Tag = "VBA CustomButtons"
    .OnAction = "ShowFillIn"
    .FaceId = 0
    .Visible = True
    End With
    MyButton.PasteFace


    The icons need to be bmp with a size of 16x24
    run the program with the bmp file as such
    CopybmpToClipboard.exe "C:\Program Files\Microsoft Visual Studio\VB98\somebitmap.bmp"

    then pasteface

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    You don't want or need to be shipping icon files along with the workbook (unless you are offering a facility for the user to pick their own). If your custom commandbar is stored in the workbook with the icons in place there's nothing else you need to do. If you build the commandbar when the workbook opens you will need to have them available. As Tommy says you could have them in cells, or shapes, on a hidden worksheet, or as faces on controls on another custom commandbar which remains invisible. Whatever you choose, it's almost certainly better to do a one-off manual job at the beginning rather than trying to import them every time.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    Tommy and Tony - Thanks
    I am going to have a go at this later and see how it goes. It all sounds likely and reasonable enough to me.

    Scott
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

Posting Permissions

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