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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadPicture() from byte array instead of a file 1

Status
Not open for further replies.

ESquared

Programmer
Dec 23, 2003
6,129
US
The title says it all. I want to distribute an Excel file that can automatically add a commandbar and button, and I'd like to provide a custom icon for the button. At this point I would simply like to have a const or array hardcoded in my module with picture data in it. After creating the commandbar and commandbarbutton, use the bytes for the .Picture property.

I could save the bytes to a temp file, then use LoadPicture() but this seems sloppy. How do I skip the saving-to-disk step? I am sincerely hoping I don't have to create a device context and such, and draw the dang thing using various API calls, since I have almost no experience with Windows API graphics and it's just a single silly picture load I am hoping to get done quickly!

I looked at GetObjectAPI but the bmBits property is returning a 0.

In order to do this task I also need to know how to retrieve the bits I've already loaded into the button's picture. I suppose I could just save a .bmp and use those raw bytes, which is fine, but I'd like the luxury of being able to display the bytes for commandbarbutton pictures without the intermediate step of saving them to a file. Plus, I'm interested to know how this all works. Perhaps I'll get into Windows graphics by bits and pieces...

Erik

PS This is perhaps an API question, so maybe I should have posted in that forum, but I don't know for sure that there's no way in Excel to do what I want.
 
You can store the picture within your vba project. One of ways, without the usage of external ImageList control, is to add Userform with as many image controls as you need, each with a picture set. The usage (standard module):
Code:
Dim cbBar As CommandBar, cbbBtn As CommandBarButton
Set cbBar = Application.CommandBars.Add
cbBar.Visible = True
Set cbbBtn = cbBar.Controls.Add
cbbBtn.Picture = UserForm1.Image1.Picture

combo
 
Hey combo, that's a great idea. Thanks.

Tony,

I want the commandbar customizations to persist after the workbook is unloaded. I'm essentialy wanting to use an Excel file as a poor man's add-in installer. But now that I've thought more, perhaps a real add-in is actually a better way to go.

One advantage of the Excel file method is that I can distribute updates by just emailing a new excel file to someone and having him open it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top