Embed Image in Add-In

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone give me some pointers on how to embed images in an Excel add-in so
that I can use them as ControlButton images?

I currently use bitmap images saved to the same folder as the add-in, but I
want to make the add-in more portable by embedding the images in the add-in
itself.

Thanks.
 
I don't have a ready answer for you and I have not seen very much
in the way of discussion in the newsgroups on this. As I think you
have discovered it can be troublesome to accomplish.
If you have to use a custom image, you might look at the
ImageList control to store/retrieve multiple images.

There are several thousand FaceID images included with Excel
and I have always been able to find one that is suitable...

Dim cmdItem as CommandBarButton
Set cmdItem = xxx.Controls.Add(Type:msoControlButton)
cmdItem.FaceId:= 123

If you need/want a quick, easy way to survey all of the FaceID's in
Excel, I have an add-in "Display Face IDs" that does the job.
Glad to send it along.
Remove xxx from my email address and include your name and
location with your request... (e-mail address removed)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Lazzaroni" <
(e-mail address removed)>
wrote in message
Can anyone give me some pointers on how to embed images in an Excel add-in so
that I can use them as ControlButton images?

I currently use bitmap images saved to the same folder as the add-in, but I
want to make the add-in more portable by embedding the images in the add-in
itself.

Thanks.
 
I do something similar, but I store the bitmaps on a hidden worksheet inside
the .xla add-in. It is simple and portable.

Regards,

Alan
 
Various ways, store or images on other images controls, hidden on main form,
or on a dummy form like an ImageList, or worksheet controls on a sheet in
your addin

- Hidden images on your main form
Set Me.CommandButton11.Picture = Me.Controls("hidden_image1").Picture

- Dummy form used like an ImageList
Dim frm As UserForm
Set frm = UserForm2
Load frm
Set Label2.Picture = frm.Controls("Image1").Picture
' Set Label2.Picture = frm.Controls(1).Picture
' Set Label2.Picture = frm.Image1Picture
Unload frm

- Worksheet controls on a sheet in your addin
could set a ref to all oleObjects on the sheet

Dim mOles as Oleobjects ' at module level

in the Initialize event
Set mOles = thisworkbook.Worksheets(1).OleObjects

'where needed
Set Me.Label1.Picture = mOles("ole_name").Object.Picture

To remove a picture from your control
Set Me.Label.Picture = Nothing


Which of the above methods might depend on the number and total file sizes
of images, each have pros & cons, eg

Hidden controls on main form is simplest but could impact form load time

Dummy ImageList form is nice 'cos you can lay out all your images on the
dummy and tab between forms to look what you've got while developing.

Worksheet image controls - best for large number / file size but also fine
for small qty

Regards,
Peter T
 
Using a UserForm to store the images worked the easiest and best for me. As
Peter mentioned, you can arrange the images in the form for easy reference,
and if you use Labels instead of Image controls, you can actually label the
pictures easily as well. The best part is that the images are preloaded and
easy to refer to, especially if you take care to name the label to give some
indication of what image it contains.

Thanks so much for your help.
 

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

Back
Top