Copying a FaceID on a userform commandbutton !

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,817
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,

I am trying to copy The Excel standard print icon on a userform command button that runs a printing procedure on clicking on it.

I have tried different approaches but without any luck.

The following code copies the icon on cell A1 of the activesheet:


Sub copy_faceid()

CommandBars(1).Controls(1).Controls("print...").CopyFace

ActiveSheet.Paste Cells(1, 1)

Application.CutCopyMode = False

End Sub


The approach above however, doesn't seem to work with userforms.

Any suggestions will be much appreciated as I have been like mad looking for a solution for a long long time.

Thanks.

Jaafar.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
On 2002-12-29 00:02, rafaaj2000 wrote:
Hi Guys,

I am trying to copy The Excel standard print icon on a userform command button that runs a printing procedure on clicking on it.

I have tried different approaches but without any luck.

The following code copies the icon on cell A1 of the activesheet:


Sub copy_faceid()

CommandBars(1).Controls(1).Controls("print...").CopyFace

ActiveSheet.Paste Cells(1, 1)

Application.CutCopyMode = False

End Sub


The approach above however, doesn't seem to work with userforms.

Any suggestions will be much appreciated as I have been like mad looking for a solution for a long long time.

Thanks.

Jaafar.

I'm not with you ??
Are you trying to copy an image off of a Commandbutton on a Userform ??
If you are then try the following little known code

SavePicture CommandButton1.Picture, "C:aa.ico"

Then just import into excel Via import
button etc.
 
Upvote 0
Hi Ivan.
I think he wants to take the face id from the commandbar button, place it on the clipboard using the copyface method, and then use it as a picture on the commandbutton. You're the API guru here! Will likely need the API to accomplish this.

:smile:
 
Upvote 0
On 2002-12-29 06:05, TsTom wrote:
Hi Ivan.
I think he wants to take the face id from the commandbar button, place it on the clipboard using the copyface method, and then use it as a picture on the commandbutton. You're the API guru here! Will likely need the API to accomplish this.

:smile:

Oh, I think I understand now :smile:
Thanks Tom
 
Upvote 0
Check whether this is any help :-

http://www.BMSLtd.co.uk (PastePicture.zip)

To do what you want manually :-
1. After pasting the icon to the worksheet, select and copy it
2. Go to the userform and add an image control
3. Go to the picture property of the image control, click in it and press Ctrl+V
 
Upvote 0
Hi Ponsonby,

I tried doing it manually and it does give a result!.However it doesn't look as expected.Anyway thank you very much for this,at least we are approaching the propper solution.

Thanks everyone else.

Jaafar.
 
Upvote 0
Hi rafaaj2000
I did find several examples using the Windows API. They were all in C and over my head. My search which yielded the best results on Google was "clipboard bitmap file api"
Have fun.
 
Upvote 0
Hi rafaaj2000

If you use Stevens routine then just use
this code to get what you want.
This will change the Picture of commandbutton2 to the Printer img.<pre/>
Const ImgFileName As String = "C:ATest.bmp"

Private Sub CommandButton1_Click()

'// Copy the FaceImage to the ClipBoard
CommandBars(1).Controls(1).Controls("print...").CopyFace
'// Save the img
SavePicture PastePicture, ImgFileName
'// Load the Img
CommandButton2.Picture = LoadPicture(ImgFileName)
'// Cleanup
Kill ImgFileName

End Sub</pre>



_________________
Kind Regards,<font size=+2><font color="red"> I<font color="blue">van<font color="red"> F M</font color="blue">oala</font><font size=1> From the City of Sails
Auck.gif

This message was edited by Ivan F Moala on 2002-12-30 02:10
 
Upvote 0
This post has helped me a lot, so I decided to register and show what I've done.

I wanted to set FaceIds to a bunch of command buttons. After trying a lot of code in the web (and the one in this OLD post), I end up using this:

Code:
Public Sub setCommandButtonFaceId(faceId As Integer, _
 ByRef control As CommandButton)
 
    Application.CommandBars.FindControl(Type:=msoControlButton, ID:=faceId).CopyFace
    
    Dim ImgFileName As String
    ImgFileName = Environ("temp") & "\tmppicture.bmp"
     
    '// Save the img
    SavePicture PastePicture(xlBitmap), ImgFileName

    '// Load the Img
    control.Picture = LoadPicture(ImgFileName)
    control.PicturePosition = 0
    
    '// Cleanup
    Kill ImgFileName
   
End Sub

The preconditions are to KNOW the face id you want to set, and have the Stephen PastePicture.zip module that you can find here:

http://www.oaltd.co.uk/excel/default.htm

Specially here: http://www.oaltd.co.uk/DLCount/DLCount.asp?file=PastePicture.zip

Hope this helps.
Best Regards
 
Upvote 0

Forum statistics

Threads
1,225,216
Messages
6,183,632
Members
453,177
Latest member
GregL65

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top