Commandbutton picture problem

J

Jim B

Hi,

I'm trying to set the picture of a commandbutton with VBA code in Excel and
I get an automation error:

-2147467259 (80004005)

Here's the code I'm using:

Dim cbDA As CommandBar
Dim cbtDA As CommandBarButton
Dim picPicture As IPictureDisp
Dim picMask As IPictureDisp

Set cbDA = Application.CommandBars("Data Analysis")

Set cbtDA = cbDA.Controls.Add(msoControlButton)
Set picPicture = stdole.StdFunctions.LoadPicture( _
"c:\corp_dev\Icon_Lib\eWorld 2000 Win\globe.ico")
With cbtDA
.Style = msoButtonIconAndCaption
.TooltipText = "Listing of available reports."
.Caption = "Reports"
.Visible = True
.Picture = picPicture
End With

I made sure the globe.ico file was correctly referenced and that stdole was
available. I even tried testing it with a common bmp file used by office
and it still failed.

What am I doing wrong?

Thanks,
 
R

RC-

Jim,
Is there a particular reason why you want to load your own picture, i.e.
does the corporate office force you to use a certain icon? If not, check
this utility out, I have been using it for about three years now and I swear
by it.

http://skp.mvps.org/faceid.htm

Once you load the add-in, all you have to do is browse for an icon that you
like and plug in the number into the .FaceID property of your menu bar

Example:

With cbtDA
.Style = msoButtonIconAndCaption
.TooltipText = "Listing of available reports."
.Caption = "Reports"
.Visible = True
.Picture = picPicture YOU WOULD REMOVE THIS ENTRY AND REPLACE
WITH THE ONE BELOW
.FaceID = 2487 THE NUMBER WOULD BE THE NUMBER THAT IS
ASSOCIATED WITH THE ICON YOU LIKE
End With


Sorry for the caps above, just wanted to make sure you saw the instructions

I hope this helps
RC-
 
J

Jim B

I wasn't being forced to use certain icons so this will work great for me.
Thanks a lot for this!
 

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