Getting listbox files to show as image

Wicked_

Board Regular
Joined
Jun 5, 2018
Messages
81
Hi.

I have a Listbox and a Image (imagebox) in my userform.
I then have a code in the listbox that gather images from a folder to the listbox.
Example, if i have 3 images called "image1, image2, image3" (in a folder), they pop-up in the listbox correctly.

But now, i would like to show those pictures in the imagebox which i have next to the listbox. So like, if i press the Image1 file from the listbox, i would like it to show the image on the imagebox.

I have searched for this alot, but havent found a relevant code that fulfills what i need.

Is there anyone that could help me with this? :)

Thanks in advance!
 
Glad to help. :)

One last question :)

I made a browse button, that allows you to select the folder you want (Code below). How do i take your code, and make it not folder restricted, but let it grabs images depending on what folder i chose with the browse button?

Browse button:

Private Sub select_Image_1_Click()


Dim MyFolder As String
Dim MyFile As String


With Application.FileDialog(msoFileDialogFolderPicker)


If .Show = -1 Then


ListBox1.Clear


TextBox1.Text = .SelectedItems(1)
MyFile = Dir(.SelectedItems(1) & "\*.jpg")
Do While MyFile <> ""


ListBox1.AddItem MyFile
MyFile = Dir
Loop
End If
End With
End Sub
 
Upvote 0
You can refer to the path in the textbox:

Code:
Me.Image1.Picture = Loadpicture(Textbox1.text & "\" & Listbox1.Value)
 
Upvote 0
You can refer to the path in the textbox:

Code:
Me.Image1.Picture = Loadpicture(Textbox1.text & "\" & Listbox1.Value)

Ahh sweet. Did not think of that one.. Perfect!

Also, is it possible to achieve the same result as i now got (which works perfectly!), but with pdf files instead of jpg files? Played around with the PDFAcro1 function, but stuck..
 
Upvote 0
I don't know how you would display a preview of a pdf file, I'm afraid.
 
Upvote 0

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