Loading a picture from a spreadsheet into a userform

PeterMac65

New Member
Joined
May 7, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi,
MickG wrote some code to load pictures from a spreadsheet into a userform. Worked well
But
I want to know how it can be adapted to load Shapes / msoPictures from a spreadsheet into a userform
I have users that are sniping and pasting pictures into a "sheet2" and i want to show all those pictures. I think the type is an msoPicture but cant be sure

Regards PeterMac

MicG said:
Your Userform should have an "Image Control" (Image1) and a "ListBox" (ListBox1).
The pictures are assumed to be on sheet2 (Change Sheet name in code as required,(2 places, sub "Pict", and "Initialize")
When you run the code the first image name in your listbox will be loaded.
After that it will change based on the Listbox selection.

Place the code below in the Userfrom Module:-
Code:
Option Explicit
Private Sub ListBox1_Click()
Call Pict(ListBox1.ListIndex)
End Sub


Private Sub UserForm_Initialize()
Dim Pic As Object
For Each Pic In Sheets("Sheet2").Pictures
If TypeName(Pic) = "Picture" Then
ListBox1.AddItem Pic.Name
End If
Next Pic
ListBox1.ListIndex = 0
Call Pict(0)
End Sub


Sub Pict(n)
Dim Ans As String
Dim rng As Excel.Range
Dim cht As Excel.ChartObject
Dim Pth As String
Dim Pic As Object
With ListBox1
Set Pic = Sheets("sheet2").Shapes(.List(n))
Pic.Copy 'Picture xlScreen, xlBitmap
Dim Strpath As String
Strpath = ThisWorkbook.Path & "\Temp.jpg"
Set cht = ActiveSheet.ChartObjects.Add(100, 0, Pic.Width, Pic.Height)
cht.Chart.Paste
cht.Chart.Export Strpath
cht.Delete
Set cht = Nothing
Me.Image1.Picture = LoadPicture(Strpath)
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Watch MrExcel Video

Forum statistics

Threads
1,132,898
Messages
5,655,858
Members
418,248
Latest member
JinxedCaspa

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
Top