Excel - Embed image into cell

Many thanks in advance for any help given:

Aprox a year ago, Excel add the function “Place in Cell” to allow images to be embedded.
Has AppleScript caught up yet and provided support to script this functionality?

I think that would depend on whether microsoft added the applescript functionality for that command or not.

You can check for yourself by searching for ‘place in cell’ or even just ‘place’ in the applescript dictionary for excel. I run an older version (2011) so I can’t look it up.

I put on my PPE and took a look at the dictionary - I couldn’t find any reference to images, pictures or anything else.

Furthermore, exploring (via Script Debugger) didn’t expose any reference to any images (whether placed in cell or floating), and the only even remotely-relevant indicator was that the ‘formula’ for a cell that has a picture is “Picture”, but no indication as to the source, nature, size, or anything else of said picture.

Seems like, yet again, Excel’s AppleScript dictionary lets us down.

FWIW, I typed ‘picture’ into script debugger and there were 106 results.

Picture’ is a class and in my version of Excel (2011), you can work with it to add a ‘floating’ image to a worksheet. In all likelihood, you can work with any type of image that Excel can. The list of these should be in Excel’s help. Note that this functionality seems to mirror the application’s own: Insert > Photo > Picture from file. Properties such as the dimensions can be set. It requires a path to the source image.

Here is a simple script that will deposit a jpeg onto the active worksheet. By default, its placement seems to be 25 units from the top and from the left. It then moves the image down and to the right.

set pdt to (path to desktop) as text
set fp to (pdt & "sample-123b.jpg" as text)

tell application "Microsoft Excel"
	tell workbook 1
		
		set newp to make new picture at the beginning of active sheet with properties {file name:fp, height:314, width:560, lock aspect ratio:true}
		--> picture 1 of active sheet of workbook 1
		
		set top of newp to 100
		set left position of newp to 200
	end tell
end tell

If you want to work with pictures later, here is a simple script that gets the picture and its properties. You should be able to set new dimensions, for example.

tell application "Microsoft Excel"
	tell workbook 1
		
		set xy to pictures of active sheet
		--> {picture 1 of active sheet of workbook 1}
		set xyz to item 1 of xy
		properties of xyz
		
	end tell
end tell

You can likely also work with ‘shapes’ and set the background of one to a picture but I haven’t tried to script that.