insert group image that consist shape and image to Userform

aap

New Member
Joined
Dec 14, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
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(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


i really appreciate with any aswers
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Which line in your code gives the subscript out of range error?

Also, note that the code specifies Sheet2 as having the images. Is this correct? Or are the images located on another sheet?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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