Save image inside of excel file for easy access in userform

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I have a userform with a bunch of labels that use a specified image (word doc icon, pdf icon, etc) and these labels in the userform are created dynamically after accessing a database. Sometimes a 1000 of these icons are generated and it takes forever. I know dynamically adding form components is slow as is but I think what is really slowing it down is that I have to keep referencing the file location for the icon's jpeg as I dynamically create them (these icons files are located on a slow network drive to make it worse!). So I have a lot going against me on this but that is why I was hoping I could possibly save the icon image to the excel file itself and embed it and then access the jpeg file image in memory since the excel file is open already. Is this doable or a solution like this exist?

My other idea was to save the file as an attachment in an access database and when we do our ADO query potentially pull that file (not sure if ADO supports this though) and use it in memory . Any other solutions would be worth considering too!

Thanks
Shaun
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,875
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
You may store some pictures in the memory, for example in Image controls with Visible = False.
Put Image control on Userform, select it, press F4 and use its Picture property to load picture manually into that control.
Then in UserForm's code try something like this:
VBA Code:
Me.Label1.Picture = Me.Image1.Picture
or that:
Code:
i = 1
Me.Controls("Label" & i).Picture = Me.Controls("Image" & i).Picture
But storing 1000+ pictures & Images looks not good as for me.

Another way is copy via code all icon files to the local %TEMP% folder to exclude slow network drive accesing.
Don't forget to remove those files at Excel closing.
 

Dermot

Board Regular
Joined
Aug 11, 2006
Messages
199
Office Version
  1. 365
Platform
  1. Windows
I have a sheet with 1600 standard Windows icons in it (used in a utility for creating a custom ribbon menu), laid out neatly in a table. They are named pic1, pic2, ...

Clicking on any of them inserts their name in a place I have specified (there is a companion sheet with a matching list of all the names that go with these icons). In your case, it could insert the icon on a form just as easily.

The workbook is not large, just over 1mb.

So yes, I think that is feasible.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,951
Messages
5,834,538
Members
430,295
Latest member
amdis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top