Solved

Assign custom face to CommandBar Control

Posted on 2002-03-26
5
395 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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