OLEobject on the sheet

R

Ryan

Dear Experts,

I have an image control on the worksheet but I couldn't
find right property name to change the path of the image
file in the macro. Actualy I used the macro recorder to
generate the code creating the image box on the sheet and
run the macro the create it automatically. The code is
like this

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Image.1",
Link:=False, DisplayAsIcon:=False, Left:=240, _
Top:=32.25, Width:=345.75, Height:= 182.25).Select

What can I do next to insert the image filename for this
control?

Thanks for your help
Ryan
 
D

Dave Peterson

This worked ok for me:

Option Explicit
Sub testme01()

Dim OLEObj As OLEObject
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("c9:d16")

With myRng
Set OLEObj = .Parent.OLEObjects.Add(ClassType:="Forms.Image.1", _
Link:=False, DisplayAsIcon:=False, Left:=.Left, _
Top:=.Top, Width:=.Width, Height:=.Height)
End With

OLEObj.Object.Picture = LoadPicture(Filename:="C:\pict.jpg")

End Sub
 

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