There's a hack-y way around to do this - basically:
- create a temp
Worksheet
- create a shape and load the picture to it and resize the picture
- create a temp
Chart and paste the re-sized picture onto it
- export the
Chart to a temp file
- delete the temp
Worksheet
- load the temp file to the
UserForm
- delete the temp file
It is a bit ghastly, but it works. You might want to consider using Application.ScreenUpdating = False whilst the code is running, but it is useful to step through the code below to see how it works.
Option Explicit
Private Sub UserForm_Initialize()
' size of thumbnail
Dim lngSide As Long
lngSide = 50
' input jpg and temp file path
Dim strInPath As String
Dim strOutPath As String
strInPath = Environ("USERPROFILE") & "\Desktop\Capture.JPG"
strOutPath = Environ("USERPROFILE") & "\Desktop\temp.JPG"
' add a temp worksheet
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add
' load picture to shape and RESIZE
Dim shp As Shape
Set shp = ws.Shapes.AddPicture(Filename:=strInPath, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoCTrue, _
Left:=20, _
Top:=20, _
Width:=lngSide, _
Height:=lngSide)
' create a chart
Dim cht As Chart
Set cht = ws.Shapes.AddChart(xlColumnClustered, _
Width:=lngSide, _
Height:=lngSide).Chart
' copy shape picture to chart and export to temp file
shp.Copy
cht.Paste
cht.Export Filename:=strOutPath, FilterName:="jpg"
' remove temp sheet (including shape and chart) with no alerts
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
' load resized temp picture to image control
With Me.Image1
.Height = lngSide
.Width = lngSide
.Picture = LoadPicture(strOutPath)
End With
' delete the temp file
Kill strOutPath
End Sub