Variable as subject of SET

L

Lucas

Hello,
I,m trying to place an image, that is in worksheet, to user form. I menaged
to do it by copying it to clipboard and than taking it from there to user
form. Everything works fine, but I want to go step forward. What i'm trying
to do is to place picture but name of the picture depends from the option
user will chose. The problem is that I use SET to chose which picture is
copied.
Code looks like this:

set pic=sheet1.image1

this is examle for one picture, but I can't do it for random name:

for example name is:

name="sheet1.image" & i

and for this case it doesen't work, please help.
 
P

Peter T

For ideas -

Private Sub UserForm_Click()
Dim sOlePic As String
Dim ole As OLEObject

sOlePic = "Image1" ' name of the image control on the sheet

Set ole = ActiveWorkbook.Worksheets("Sheet1").OLEObjects(sOlePic)
Set Me.Image1.Picture = ole.Object.Picture
Me.Image1.AutoSize = True

End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top