Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2004, 07:24 PM
amc amc is offline
Authorized User
 
Join Date: Feb 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default FaceID and icons

I am starting development in Windows Forms .NET and I would like to know if there is any means to "extract" the FaceID from Office (say, Access, Excel,...) and convert to individual graphic files (gif, bmp,...), in order to reuse them in the .NET environment....

thanks


thanks
antonio
__________________
thanks
antonio
 
Old August 31st, 2004, 01:09 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi. I'm not sure what you mean by extracting FaceID. FaceID is just a number, like 17 or 19. If you mean you need the image on the button, then there's a way. First of all, standard MS images for icons consist of a picture itself and so called mask - "The mask image determines which parts of the button image are transparent. Always set the mask after you have set the picture for a CommandBarButton object" (from MS Excel VBA Help)
Here's a procedure to send both: a picture and a mask of a button to .bmp files :
Code:
Sub GetButtonImageAndMask()
    Dim picPicture As IPictureDisp
    Dim picMask As IPictureDisp
    'This will reference the first button of the first commandbar.
    With Application.CommandBars.FindControl(msoControlButton)
        'Get the button image and mask of this CommandBarButton object.
        Set picPicture = .Picture
        Set picMask = .Mask
    End With

    'Save the button image and mask in a folder.
    stdole.SavePicture picPicture, "C:\...(your path)...\ImageName.bmp"
    stdole.SavePicture picMask, "C:\...(your path)...\MaskName.bmp"
End Sub
If you need to reference specific buttons, use FindControl method of the CommandBars collection.

The second routine creates a new command bar with a button and sets button's face using a picture from a file.
Code:
Sub ChangeButtonImage()
    Dim c As CommandBar
    Dim cb As CommandBarButton
    Dim picPicture As IPictureDisp
    Dim picMask As IPictureDisp   'you can also change the mask    
    Set picPicture = stdole.StdFunctions.LoadPicture( _
        "c:\...(your path)...\iconName.bmp")
    'optional - only of you have a mask file
    Set picMask = stdole.StdFunctions.LoadPicture( _
        "c:\...(your path)...\maskName.bmp")
    On Error Resume Next
    Application.CommandBars("BarName").Delete
    Set c = Application.CommandBars.Add("BarName", msoBarFloating, False, True)
     c.Enabled = True
     c.Visible = True
    Set cb = c.Controls.Add(msoControlButton, 1)
        cb.Style = msoButtonIcon 
        cb.Tag = "ButtonTest"
       'Set the picture  
        cb.Picture = picPicture
       'Set the mask
        cb.Mask = picMask
        cb.OnAction = "ThisWorkbook.Test"
        Set cb = Nothing
        Set c = Nothing
End Sub
Hope it helps.

Regards,
Maria

There's always an answer. Your task is to find it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabled icons EricJ VB How-To 0 July 12th, 2005 09:51 AM
Icons in Menu ashu_from_india Pro VB 6 2 June 3rd, 2005 10:58 PM
Menu Icons snowy0 VB.NET 2002/2003 Basics 2 September 28th, 2004 08:09 PM
Using icons within a userform Stubby Excel VBA 2 July 7th, 2004 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.