Solved

Assign custom face to CommandBar Control

Posted on 2002-03-26
5
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

615 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