How to add an image to a worksheet programmatically

  • Thread starter Thread starter mjohnson
  • Start date Start date
M

mjohnson

I am trying automate adding a picture to an excel sheet using JScript
(I would imagine the language shouldn't matter that much). After doing
quite a bit of research I tried writing the following code but I get an
error saying that the 'Pictures' collection is null or not an object.
I can't seem to figure out what I should be doing:

var book = new ActiveXObject("OWC10.Spreadsheet");
var sheet = book.Worksheets[1];
var range = sheet.Range("A1");

range.Activate();
sheet.Pictures.Add( PATH_TO_LOGO_BMP );

Any suggestions? thanks for your help!
 
Use something like this

ActiveSheet.Shapes.AddPicture "C:\Data\Skate.jpg", msoTrue, _
msoFalse, 100, 100, 100, 50
 
Thanks for your response but it still doesn't work. It seems that
'Shapes' isn't a valid member either. This is what I tried:

sheet.Shapes.AddPicture(PATH_TO_LOGO,true,false,100,100,100,50);

Not sure if the problem is 'ActiveSheet' or not. I realize that
ActiveSheet is valid in VBA, but I tried 'book.ActiveSheet' but that
didn't work either. Using the ObjectBrowser is less than satisfactory
(it doesn't even give you a view into the Cell object). It's very
frustrating trying to find documentation on how to use the Excel object
effectively. A lot of guess work....
 

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

Back
Top