ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OLEobject on the sheet (https://www.excelbanter.com/excel-programming/273397-oleobject-sheet.html)

Ryan[_6_]

OLEobject on the sheet
 
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

Dave Peterson[_3_]

OLEobject on the sheet
 
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


Ryan wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com