Userform picture based on a combobox selection

Watchdawg

Board Regular
Joined
Jan 21, 2015
Messages
84
Good morning all, I've seen a few posts on here but haven't found a situation similar. On Sheet1, I have a list of all employees. On a local drive I have a picture of all employees which I would like to hyperlink to the name...that's the easy part.
My userform has a combobox that's populated by RowSource "Employees", which is the name of the list of employees. Once the user selects a name, I would like the userform to automatically find that name in Sheet1 and display the photo that is hyperlinked to that name. I've never worked with an image in this way so I'm not even sure where to start, so any assistance would be GREATLY appreciated!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

Any reason to hyperlink the name ?

If the image name is similar to employee name you can directly use below code. Please test and confirm.
image1 is Image Control and ComboBox1 is Combo box used on user form.

VBA Code:
Private Sub ComboBox1_Change()
    Dim imagePath As String
    imagePath = ThisWorkbook.Path & "\images\" & ComboBox1.Value & ".jpg"
    Image1.Picture = LoadPicture(imagePath)
End Sub
 
Upvote 0
Solution
Hi,

Any reason to hyperlink the name ?

If the image name is similar to employee name you can directly use below code. Please test and confirm.
image1 is Image Control and ComboBox1 is Combo box used on user form.

VBA Code:
Private Sub ComboBox1_Change()
    Dim imagePath As String
    imagePath = ThisWorkbook.Path & "\images\" & ComboBox1.Value & ".jpg"
    Image1.Picture = LoadPicture(imagePath)
End Sub
That worked perfectly. I was attempting the hyperlinks because it would be easier than renaming all of the photos. That said, there aren't THAT many photos, so a little extra work on the front end will make things much easier on the back end. Thank you!!
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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
Back
Top