Save image inside of excel file for easy access in userform

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
554
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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,805
Office Version
  1. 2016
  2. 2010
  3. 2007
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
85
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,251
Messages
5,600,541
Members
414,386
Latest member
PARAMATHMA SENTHILNATHAN

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