Using VBA to load a picture and paste it to the clipboard

E

Eric Crichlow

Hi all,

I'm trying to create a custom toolbar in PowerPoint.

To do this, I first call CommandBars.Add to create a new,
independent toolbar. No problem.

Next, I add a button to the toolbar by calling
CommandBar.Controls.Add. No problem.

Then I set up the button by setting various properties on it (Tag,
Caption, Style, Visible). No problem. The toolbar shows up with the
new button, which has the correct tag on it.

But I want to add a little graphic to the button, next to the tag.

Okay, CommandBarButton has a member called PasteFace, which pastes
the contents of the clipboard to the button. Works great if I use
another program to copy the desired image to the clipboard before my
VBA code pastes it to the button.

But my image is saved as a file, and I need to load in that image
and paste it to the clipboard from within my VBA code, so that the
PasteFace call will work.

And I can't figure out how to do it!

CommandBarButton doesn't have a "Picture" property which I could
just set to get the image into it. It seems that the only way to get
the image on the button is with PasteFace.

CommandButton has a "Picture" property. So maybe I could create a
CommandButton, set the image for it, copy it's face to the clipboard,
then paste that face to my CommandBarButton. Nope, CommandButton
doesn't have a CopyFace call to copy its face to the clipboard.

So how do I set the image in a CommandBarButton from a file?

....Thanx...
....Eric...
 
S

Steve Rindsberg

Eric Crichlow said:
Hi all,

I'm trying to create a custom toolbar in PowerPoint.

To do this, I first call CommandBars.Add to create a new,
independent toolbar. No problem.

Next, I add a button to the toolbar by calling
CommandBar.Controls.Add. No problem.

Then I set up the button by setting various properties on it (Tag,
Caption, Style, Visible). No problem. The toolbar shows up with the
new button, which has the correct tag on it.

But I want to add a little graphic to the button, next to the tag.

Okay, CommandBarButton has a member called PasteFace, which pastes
the contents of the clipboard to the button. Works great if I use
another program to copy the desired image to the clipboard before my
VBA code pastes it to the button.

But my image is saved as a file, and I need to load in that image
and paste it to the clipboard from within my VBA code, so that the
PasteFace call will work.

And I can't figure out how to do it!

CommandBarButton doesn't have a "Picture" property which I could
just set to get the image into it. It seems that the only way to get
the image on the button is with PasteFace.

CommandButton has a "Picture" property. So maybe I could create a
CommandButton, set the image for it, copy it's face to the clipboard,
then paste that face to my CommandBarButton. Nope, CommandButton
doesn't have a CopyFace call to copy its face to the clipboard.

So how do I set the image in a CommandBarButton from a file?

Create a new presentation under program control
Import the graphic into it from file
Copy the graphic to put it on the clipboard
Set the presentation's .Saved property to True
Close the presentation

If you don't delete the toolbar when the add-in closes, you'll only need to do
this once.

You can even open the temporary presentation w/o a window to speed things up
and cut down on the visual dancing.


================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top