File thumbnail on userform

yinkajewole

Active Member
Joined
Nov 23, 2018
Messages
281
how can one display the thumbnails of files that are in a listbox especially for .jpg, .cdr?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Something like this:

bRsJAA5.jpg


Code:
Private Sub UserForm_Initialize()
ListBox1.AddItem "labels_neg.jpg"
ListBox1.AddItem "charts.gif"
ListBox1.AddItem "times.jpg"
ListBox1.AddItem "barg.jpg"
End Sub


Private Sub UserForm_Click()
Dim c As Control, n%, i%
n = Me.ListBox1.ListCount
For i = 1 To n
    Set c = Me.Controls.Add("Forms.image.1", "mImg" & i, True)
    c.PictureSizeMode = fmPictureSizeModeStretch
    c.Width = Me.Width / n
    c.Left = (i - 1) * Me.Width / n
    c.Picture = LoadPicture("c:\pub\" & Me.ListBox1.List(i - 1))
Next
End Sub
 
Upvote 0
Something like this:

bRsJAA5.jpg


Code:
Private Sub UserForm_Initialize()
ListBox1.AddItem "labels_neg.jpg"
ListBox1.AddItem "charts.gif"
ListBox1.AddItem "times.jpg"
ListBox1.AddItem "barg.jpg"
End Sub


Private Sub UserForm_Click()
Dim c As Control, n%, i%
n = Me.ListBox1.ListCount
For i = 1 To n
    Set c = Me.Controls.Add("Forms.image.1", "mImg" & i, True)
    c.PictureSizeMode = fmPictureSizeModeStretch
    c.Width = Me.Width / n
    c.Left = (i - 1) * Me.Width / n
    c.Picture = LoadPicture("c:\pub\" & Me.ListBox1.List(i - 1))
Next
End Sub

thanks, i love this, it works for picture files, what about files like pdf, cdr, psd? is there a workround for this?
 
Last edited:
Upvote 0
Here is my idea:


  • Insert the PDF in the worksheet as an OLE object
  • Paste this as an image
  • Paste the image into a chart
  • Export the chart to a picture file
  • Load the picture into the user form.

I will be back later with the code.
 
Upvote 0
The PDF code:

pbQ9kd2.png


Code:
' regular module
Public s$
Sub ThumbNail()
Dim pdfobj
s = "c:\pub\MyPicsat.jpg"   ' save to disk with this path
Set pdfobj = ActiveSheet.OLEObjects.Add(Filename:="c:\pub\gt.pdf", link:=True, displayasicon:=False)
pdfobj.Copy
ActiveSheet.PasteSpecial Format:="Imagem (PNG)", link:=False, displayasicon:=False
ExportPic
End Sub

Sub ExportPic()
Dim MyChart$, MyPicture$, PicWidth As Long, PicHeight&, sname$
Application.ScreenUpdating = False
MyPicture = Selection.Name
sname = ActiveSheet.Name
With Selection
    PicHeight = .ShapeRange.Height
    PicWidth = .ShapeRange.Width
End With
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=sname
Selection.Border.LineStyle = 0
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)
With ActiveSheet
    With .Shapes(MyChart)
        .Width = PicWidth
        .Height = PicHeight
    End With
    .Shapes(MyPicture).Copy
    With ActiveChart
        .ChartArea.Select
        .Paste
    End With
    .ChartObjects(1).Chart.Export Filename:=s, FilterName:="jpg"
    .Shapes(MyChart).Cut
End With
Application.ScreenUpdating = True
End Sub

Code:
' user form module
Private Sub UserForm_Click()
Dim c As Control
Me.Caption = "PDF Thumbnail"
ThumbNail
Set c = Me.Controls.Add("Forms.image.1", "mImg1", True)
c.PictureSizeMode = fmPictureSizeModeStretch
c.Width = Me.Width * 0.95
c.Left = 10
c.Height = Me.Height * 0.95
c.Picture = LoadPicture(s)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
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