Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert picture in Excel sheet automatically 3

Status
Not open for further replies.

gkratnam

Programmer
Aug 9, 2007
37
US
Trying to add a logo to Excel worksheet using the Sheet.Pictures.Insert property. But 'Insert' is not recognized.

Please see here for the code.

excelforum2_wrpnfy.png



'Insert' is not coming up as a property here. Is there any setup missing?

excelforum1_xhwtjf.png


Need to add a logo(.bmp or .png) in a specific cell. Is there any other way to do this? Please assist.

Thanks!
 
You probably want the Shapes collection, not the Pictures collection. Try Shapes.AddPicture.

Tamar
 
Thanks for the suggestion Tamar!

It asks for many other parameters.

It would not allow to skip any, says "parameters are not optional".

Is there any other simpler way to do this?

excelforum3_e0sc2n.png
 
Lets do this step by step:
If you create an Excel Application automation server (aka Excel.Application) many properties and methods intellisense finds are public, so you can access and use them.

Code:
oExcel = CREATEOBJECT("Excel.Application")
? oExcel.Workbooks.Count

You get a count of 0. That's the simplest reason you cannot access anything on the level of a Workbook, even less so of a Sheet. No workbook, no sheet, no pictures.

Lets see:
excel1_i3ulok.png


A Pictures collection doesn't show. It has to do with how VFP drills down the typelib information, perhaps. Anyway, it's always good to try to drill deeper by loading an object reference into a variable:
Code:
oExcel.Workbooks.Add()
oSheet = oExcel.Workbooks(1).Sheet(1)
excel2_xoacji.png


We get nearer. Now Pictures show up, but take a close look, its icon has a lock.

That means it's not so private you don't get to see it at all, but it's protected against access from "outside". Well, lets be the Pictures, ie again load the Pictures object into a VFP variable:
Code:
oPictures = oSheet.Pictures
excel3_rierhp.png


Now the Insert method becomes visible and is public. I think it's a matter from which level you ask for access. That's not normal in other languages, especially not when you use the Office object model more directly. In VBA you can do:
Code:
Application.Workbooks.Add().Sheets(1).Pictures.Insert ("C:\Pictures\mylogs.png")

Which gives you another solution path, if all else fails, use VBA within the Office application you automate.
 
That did it!!! [smile]

Thanks so much for the very detailed explanation Chriss!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top