How to insert group image with same method with insert chart to userform with comman box click.
i try code from MickG (best regard) on post loading a picture from spreadsheet into userform
with the code
but run time error subscript out of range
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
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)
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
i really appreciate with any aswers
i try code from MickG (best regard) on post loading a picture from spreadsheet into userform
with the code
but run time error subscript out of range
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
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)
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
i really appreciate with any aswers