Picture in VB (again)


Posted by Nicke on January 15, 2002 7:30 AM

Since no one answered my last question i try again with a better code snippet. I REALLY must have this to work so I hope someone can help me.

I have a Frame in Excel with a picture. If I type following code in VBA it returns -1056632835 (imgbutton1 is what I've named the frame)

? imgbutton1.picture

If I try this in VB with following snippet I get an "Automation error" for the Picture property.

'<&LT;START CODE>><p> Dim xl As Excel.Application
Dim img As MSForms.Frame
Dim pic As Object

Set xl = GetObject(, "Excel.Application")
Set img = xl.ActiveSheet.OLEObjects(1).object

'This results in an error...
MsgBox img.Picture
'<&LT;END CODE>><p>I know img have a correct pointer to the frame because I can for example move the frame from VB. It's just the Picture property that fails.

Thanx in advance.

Posted by Jerid on January 15, 2002 8:20 AM

Did you try placing the Excel Object Variable in front of the Excel objects and functions.? (xl.)

xl.Img.Picture = xl.LoadPicture("c:\pictures\inactive.gif")

Jerid

Set xl = GetObject(, "Excel.Application") Set img = xl.ActiveSheet.OLEObjects(1).object 'This results in an error... MsgBox img.Picture

Posted by Damon Ostrander on January 15, 2002 9:50 AM

Hi Nicke,

First, I guess I'm wondering why you pasted the picture into Excel as an OLE object in a frame rather than as a picture (Shape object)? If pasted as a picture then it can be easily referred to as:

Set pic = xl.ActiveSheet.Shapes("Picture1")

and of course you can name the picture anything you want using the Name box that is above cell A1.

Second, I would not expect MsgBox img.Picture to work because MsgBox only displays text, not pictures, and I believe the Picture property yields a StdPicture object, not a text string.

Damon Set xl = GetObject(, "Excel.Application") Set img = xl.ActiveSheet.OLEObjects(1).object 'This results in an error... MsgBox img.Picture

Posted by Nicke on January 15, 2002 12:16 PM

It's too complexed to describe here but a frame was the only thing I could use. I could have used an Image control instead but it's the same error there. What I don't can use is a shape object, I think that object is part of the Excel object library and has no events like mousemove etc which I really need. I'm not really sure how Excel works with this, the control I put on the sheet is part of MSForms but you can refer it with the shape or OLEObject but to get the events you have to refer it with oleobject.object.

There is something wrong here but I don't know what.

BTW the msgbox works (if img.picture didn't returned Automation error of course).



Posted by Nicke on January 15, 2002 12:19 PM

I have not tried that (but I will at work tomorrow). But I can't see what different it will make.