Thumbnail preview in userform

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,138
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

I have been looking for a code that will show the windows preview image in an image in a userform.

I havent had any luck finding out much about this. But i do see people have had sucess.

The plan was going to be, when i clicked on a command button, it would show the preview of the file from the specified file directory.

Am i wasting my time trying to find this, or can anyone help.

Thanks

Dave
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Well, I imagine it depends on the file, and whether your system is already set up to preview these files, but there is this: Extract Thumbnail preview from file

thumbnail-gif.95077
 
Upvote 0
Solution
Well ... here's a small project from my toolbox that hopefully will assist you :

VBA Code:
Private Sub CommandButton1_Click()
Dim i As Integer, resim, cevap As String

If ListBox1.ListIndex = -1 Then
    MsgBox "The listbox item isn't selected to delete !", vbCritical, ""
   Exit Sub
   End If
   resim = ThisWorkbook.Path & "\"
    If ListBox1.ListIndex >= 0 Then
     cevap = MsgBox("Entry will be deleted. ... Are you sure ?", vbYesNo)
       If cevap = vbYes Then

For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
    Kill ThisWorkbook.Path & "\" & ListBox1.Value
    ListBox1.RemoveItem (i)
    If ListBox1.ListCount = 0 Then
     Image1.Picture = LoadPicture("")
     End If
    End If
Next i
        
    End If
    End If
End Sub

Private Sub CommandButton2_Click()
Dim dosya, cevap, resim As String
    ChDir "C:\"
    dosya = Application.GetOpenFilename(FileFilter:="," & "*.jpg", _
    Title:="Lütfen resim seçimi yapýnýz")
    resim = ThisWorkbook.Path & "\"
    
    If dosya = False Then
    Exit Sub
    Else
    
    Image3.Picture = LoadPicture(dosya)
    cevap = MsgBox("The selected picture will be added to the folder... Are you sure ?", vbYesNo)
    If cevap = vbYes Then
    SavePicture Image3.Picture, resim & GetFileName(CStr(dosya))
    Else
     Image3.Picture = LoadPicture("")
    Exit Sub
   End If
    End If
    ListBox1.Clear
    UserForm_Initialize
    Image3.Picture = LoadPicture("")
End Sub

Private Sub Image1_Click()
Unload Me
UserForm1.Show
End Sub

Function GetFileName(dosya As String)
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    GetFileName = fso.GetFileName(dosya)
End Function

Private Sub Image3_Click()
Unload Me
UserForm1.Show
End Sub

Private Sub ListBox1_Click()
    Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & ListBox1.Value)
    
End Sub

Private Sub SpinButton1_SpinDown()
On Error Resume Next
If ListBox1.ListIndex = ListBox1.ListCount - 1 Then Exit Sub
With Me.ListBox1
        .ListIndex = .ListIndex + 1
    End With
 End Sub

Private Sub SpinButton1_SpinUp()
On Error Resume Next
If ListBox1.ListIndex = 0 Then Exit Sub
With Me.ListBox1
        .ListIndex = .ListIndex - 1
    End With
    End Sub

Private Sub UserForm_Initialize()
Dim fso As Object, dosyam As Variant
    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each dosyam In fso.GetFolder(ThisWorkbook.Path).Files
    evn = fso.GetExtensionName(ThisWorkbook.Path & "/" & dosyam.Name)
    If evn = "jpg" Then ListBox1.AddItem dosyam.Name
    If ListBox1.ListCount > 0 Then
    ListBox1.Value = ListBox1.List(0)
    End If
    Next
    Set fso = Nothing
End Sub

Download workbook : Internxt Drive – Private & Secure Cloud Storage
 
Upvote 0
Well ... here's a small project from my toolbox that hopefully will assist you :

VBA Code:
Private Sub CommandButton1_Click()
Dim i As Integer, resim, cevap As String

If ListBox1.ListIndex = -1 Then
    MsgBox "The listbox item isn't selected to delete !", vbCritical, ""
   Exit Sub
   End If
   resim = ThisWorkbook.Path & "\"
    If ListBox1.ListIndex >= 0 Then
     cevap = MsgBox("Entry will be deleted. ... Are you sure ?", vbYesNo)
       If cevap = vbYes Then

For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
    Kill ThisWorkbook.Path & "\" & ListBox1.Value
    ListBox1.RemoveItem (i)
    If ListBox1.ListCount = 0 Then
     Image1.Picture = LoadPicture("")
     End If
    End If
Next i
       
    End If
    End If
End Sub

Private Sub CommandButton2_Click()
Dim dosya, cevap, resim As String
    ChDir "C:\"
    dosya = Application.GetOpenFilename(FileFilter:="," & "*.jpg", _
    Title:="Lütfen resim seçimi yapýnýz")
    resim = ThisWorkbook.Path & "\"
   
    If dosya = False Then
    Exit Sub
    Else
   
    Image3.Picture = LoadPicture(dosya)
    cevap = MsgBox("The selected picture will be added to the folder... Are you sure ?", vbYesNo)
    If cevap = vbYes Then
    SavePicture Image3.Picture, resim & GetFileName(CStr(dosya))
    Else
     Image3.Picture = LoadPicture("")
    Exit Sub
   End If
    End If
    ListBox1.Clear
    UserForm_Initialize
    Image3.Picture = LoadPicture("")
End Sub

Private Sub Image1_Click()
Unload Me
UserForm1.Show
End Sub

Function GetFileName(dosya As String)
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    GetFileName = fso.GetFileName(dosya)
End Function

Private Sub Image3_Click()
Unload Me
UserForm1.Show
End Sub

Private Sub ListBox1_Click()
    Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & ListBox1.Value)
   
End Sub

Private Sub SpinButton1_SpinDown()
On Error Resume Next
If ListBox1.ListIndex = ListBox1.ListCount - 1 Then Exit Sub
With Me.ListBox1
        .ListIndex = .ListIndex + 1
    End With
 End Sub

Private Sub SpinButton1_SpinUp()
On Error Resume Next
If ListBox1.ListIndex = 0 Then Exit Sub
With Me.ListBox1
        .ListIndex = .ListIndex - 1
    End With
    End Sub

Private Sub UserForm_Initialize()
Dim fso As Object, dosyam As Variant
    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each dosyam In fso.GetFolder(ThisWorkbook.Path).Files
    evn = fso.GetExtensionName(ThisWorkbook.Path & "/" & dosyam.Name)
    If evn = "jpg" Then ListBox1.AddItem dosyam.Name
    If ListBox1.ListCount > 0 Then
    ListBox1.Value = ListBox1.List(0)
    End If
    Next
    Set fso = Nothing
End Sub

Download workbook : Internxt Drive – Private & Secure Cloud Storage
Thanks for that, i tried it, and it seems to not load anything into the listbox unless its a jpeg.
 
Upvote 0
I haven't looked at it for a while, but what I believe it does is show previews to those files that your computer already has set up to preview. So if you don't have a PDF previewer installed (like Adobe, for example), then all it will show is the icon image, I believe. You can see from the screen capture I posted how it works on my computer. Some show, and some don't, but that's exactly what I would see if I were looking at in Explorer.

What file types were you hoping to preview?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,746
Members
453,370
Latest member
juliewar

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