Solved

Assign custom face to CommandBar Control

Posted on 2002-03-26
5
389 Views
Last Modified: 2010-05-18
Hello all,
how can I assign my own custom face to a CommandBar Control in Excel ?
I know already about CopyFace and PasteFace methods,
but this enables my only to use all regularly existing faces in Excel,
but NOT my onw  custom face (set the FaceId in some way, assigning a own symbol,icon,...).
Is it possible somehow ?
Thanks in advance
Greetings catrice
0
Comment
Question by:catrice
5 Comments
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hello Catrice,

saw this one open from you profile, this is a snippet from Stephen Bullen Excel guru

-----------------------------
I'm going to need this myself soon, so I had a go and came up with the following.  Actually I was surprised how easy it was (if you're happy playing with the API <g>) - I was expecting something much harder.  In the example below, I'm
copying a bitmap from an Image control on a UserForm to the Standard commandbar (in my tests, in Excel):


Option Explicit

 'Open, Empty, Populate and Close the clipboard
 Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As
Long
 Private Declare Function EmptyClipboard Lib "user32" () As Long
 Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As
Long, ByVal hMem As Long) As Long
 Private Declare Function CloseClipboard Lib "user32" () As Long

 'Create a copy of the image's bitmap
 Declare Function CopyImage Lib "user32" (ByVal handle As Long, ByVal un1 As
Long, ByVal n1 As Long, ByVal n2 As Long,
ByVal un2 As Long) As Long

 'Constants used in API calls
 Const IMAGE_BITMAP = 0
 Const CF_BITMAP = 2

Function CopyImageToClipboard(oImage As Image) As Boolean

 Dim hCopy As Long, hClip As Long, h As Long

 hCopy = CopyImage(oImage.Picture.handle, IMAGE_BITMAP, 0, 0, 0)

 hClip = OpenClipboard(0&)
 If hClip > 0 Then
    h = EmptyClipboard
    h = SetClipboardData(CF_BITMAP, hCopy)
    hClip = CloseClipboard
    CopyImageToClipboard = True
 End If

End Function


Sub Test()

 Dim oBtn As CommandBarButton, i As Integer

 Load UserForm1

 If CopyImageToClipboard(UserForm1.Image1) Then
    Application.CommandBars("Standard").Controls(2).PasteFace
 End If

 Unload UserForm1

End Sub

BTW, the API calls to do the opposite (i.e. create a Picture object from
whatever's on the clipboard) is demonstrated in
PastePicture.zip on the Excel page of my web site.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk
-----------------------------

HAGD:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
let me know if it works since i'm going to need it in the future :)
0
 

Author Comment

by:catrice
Comment Utility
Hi Bruintje,
I tested, but get problems when performing the 'PasteFace' method: "Method 'PasteFace' of object CommandBarButton failed". Seems the clipboard data are not quite correct. If I try to paste it in some little graphic program, there IS something in clipboard, but I get also an error.
But the way seems the right one... I will evaluate more on occasion...
greet. catrice
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi catrice,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

catrice, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now