Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applying a bitmap to a controlbarbutton....

Status
Not open for further replies.

Thingol

Technical User
Jan 2, 2002
169
Hi, I'm trying to make a custom toolbar with a button on it. The button should have a bitmap on it. Everything goes well, until I have to actually apply the bitmap to the button. I've tried this:

'The bitmap is in the same directory as the workbook, so in order
'to find the directory of the bitmap:

dim Bitmap
Bitmap = CStr(ThisWorkbook.Path)


'Then to set the properties of the button:
With ctlNewButton
.Width = 130
.Height = 52
.Picture = LoadPicture(Bitmap & "\Bitmap.bmp")
End With


Now an error message pops up, when I run this:
(this is a translation from Dutch):

Error 438
This property or method is not supported by this object.

The error message refers to the line:
.Picture = LoadPicture(Bitmap & "\Bitmap.bmp")

I think the .picture property isn't valid for ctlNewButton, except I don't know if there is any other way to assign a bitmap to a controlbarbutton.

Help, anybody?
 
If you don't mind doing it manually, copy the bitmap to teh clipboard, go to Tools | Customize, and then select the button you want to apply the bitmap to, right click and select Paste Button Image.

AC
 
Hm, I do need ti to be in the code, since the application has to work on different computers, so it needs to add the button every time the workbook is opened, and remove it when it is closed.

However, I did try to do it manually with the macro recorder on, hoping I would then be able to use the generated code. Now, I'm not sure if I'm doing something wrong, but I tried using Tool|Customize, except I then couldn't find the new button I had generated. Thus, I couldn't apply the bitmap on the button in this way. Where should I be able to find the new button?
 
Ok, so now I have been able to paste the picture on the button mannually, however, the macro recorder doesn't record the action of the actual pasting, so when I run the recorded macro, it just creates a toolbar with a new button on it. Without the picture. Ideas anyone?
 
Why create the toolbar everytime. Can you create the toolbar manually, attach it to the appropriate workbook and have your coded make it visible on opening and invisible on closing ?

AC
 
I possibly could, however 2 questions arise:

1) How would the attachment process work?
2) I've tried to apply a bitmap, which is a bit larger than the standard iconsize. The program just scales the bitmap down in order to fit the size of the old icon, instead of the (larger) size of the button. How can I let the bitmap be stretched all over the controlbutton?
 
To attach a toolbar to a workbook, have that Workbook as the active WB, and your custom toolbar prepared, select Tools, Customize and in the resultant dialog select the Toolbars tab, click on the Attach button, and you can the copy any of your custom toolbars to the pane on the right which attaches them to the workbook.

As far as I know the toolbar button bitmap size is fixed, regardless of how it is applied.

AC
 
Is it? Well, so be it then. I'll just have to make it text or something.
Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top