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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,212,931
Messages
6,110,745
Members
448,295
Latest member
Uzair Tahir Khan

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