Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Assign custom face to CommandBar Control

Posted on 2002-03-26
5
Medium Priority
?
414 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
ID: 7287530
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
ID: 7287531
let me know if it works since i'm going to need it in the future :)
0
 

Author Comment

by:catrice
ID: 7287584
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
ID: 7637881
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
ID: 7754752
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

783 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