PDA

View Full Version : Insert a picture in an multiple image control with one click based on dropdown list



jezrahman
03-31-2019, 09:53 AM
I am new to VBA and i don't know what should i do. I have an excel file with dropdown (combo Box). When a value in dropdown list is selected and have it inserted into a specific cell, image control (ActiveX Control) display an image with a name matching data from a cell. So far the image control (ActiveX Control) works perfectly. However, I don't know what commands are needed when there is more than one control image in my worksheet. For example, when I select a specific value from the dropdown list, the control 1 image will display the image "A" and image control 2 will display the image "B" and so on based on the respective cell references.

I've attached a sample workbook to illustrate what I'm trying to achieve here.

Thanks for help anyone. I really appreciate any help that you can provide!

大灰狼1976
03-31-2019, 07:18 PM
Hi jezrahman!
Welcome to vbax forum.
Please refer to the attachment.

Sub combo()
Dim NamaData, i&, pth$
Application.ScreenUpdating = False
NamaData = Array([f7], [i7], [l7], [o7])
For i = 0 To 3
pth = ActiveWorkbook.Path & "\Photo\" & NamaData(i) & ".jpg"
If Dir(pth) = "" Then pth = ActiveWorkbook.Path & "\Photo\NA.jpg"
Me.OLEObjects("Image" & i + 1).Object.Picture = LoadPicture(pth)
Next i
Application.ScreenUpdating = True
End Sub