Solved

Assign custom face to CommandBar Control

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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