PeterMac65
New Member
- Joined
- May 7, 2020
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Hi
I have a form with ListBox1 and Image1 objects
ListBox1 contains the names of 5-6 images
When a listbox item is selected i want to show the picture in "Image1"
Seems simple but I can't figure how to get the image from the worksheet into the the Userform
Can someone please help me. (NOTE: I copied and pasted an image to show what i'd like to achieve)
Regards PeterMac
Option Explicit
Private Sub ListBox1_Click()
Call Pict(ListBox1.ListIndex)
End Sub
Private Sub UserForm_Initialize()
Dim Pic As Object
Dim x As Integer
x = 0
For Each Pic In Sheets("Cost").Shapes 'Pictures
If TypeName(Pic) = "Shape" Then
If Left(Pic.Name, 7) <> "Comment" Then
ListBox1.AddItem Pic.Name
x = x + 1
End If
End If
Next Pic
Debug.Print x
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("Cost").Shapes(.List)
Pic.Copy 'Picture xlScreen, xlBitmap
Debug.Print Pic.Name
Set cht = ActiveSheet.ChartObjects.Add(100, 0, Pic.Width, Pic.Height)
' Me.Image1.Picture = "THIS IS THE BIT I DONT KNOW"
Set cht = Nothing
End With
End Sub
I have a form with ListBox1 and Image1 objects
ListBox1 contains the names of 5-6 images
When a listbox item is selected i want to show the picture in "Image1"
Seems simple but I can't figure how to get the image from the worksheet into the the Userform
Can someone please help me. (NOTE: I copied and pasted an image to show what i'd like to achieve)
Regards PeterMac
Option Explicit
Private Sub ListBox1_Click()
Call Pict(ListBox1.ListIndex)
End Sub
Private Sub UserForm_Initialize()
Dim Pic As Object
Dim x As Integer
x = 0
For Each Pic In Sheets("Cost").Shapes 'Pictures
If TypeName(Pic) = "Shape" Then
If Left(Pic.Name, 7) <> "Comment" Then
ListBox1.AddItem Pic.Name
x = x + 1
End If
End If
Next Pic
Debug.Print x
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("Cost").Shapes(.List)
Pic.Copy 'Picture xlScreen, xlBitmap
Debug.Print Pic.Name
Set cht = ActiveSheet.ChartObjects.Add(100, 0, Pic.Width, Pic.Height)
' Me.Image1.Picture = "THIS IS THE BIT I DONT KNOW"
Set cht = Nothing
End With
End Sub