Excel Embed Images

Many thanks in advance for any help given:

Approx a year ago, Excel add the function “Place in Cell” to allow images to be embedded into the cell. I cannot find any reference to that function in Excel Directory.

Im using Excel version 16.90.2

However, I have written a Script that places floating images above the relevant cells. These can then be embedded by selecting the image and clicking on the “Place in cell” pops-up box next to it. Is there anyway this can be done by using the keystroke technique?

Thanks

I wrote it without keystroke command.

http://piyocast.com/as/archives/16964

Many Thank Piyomaru but I can’t get this to work.

I get a error
error “Microsoft Excel got an error: Parameter error.” number -50

from this line on code
user picture of aPicShape picture file anImagePOSIX

Microsoft Excel 16.92 + macOS 13.7.2 and macOS 15.2beta works well for me.
Both machines are Apple Silicon Mac.

Some image file path may have space or special character in it.

Write here the image full path you selected.

tell current application

offset of “A” in “ABCDEFGHIJKLMNOPQRSTUVWXYZ”

→ 1

(1, 2)

end tell

tell application “Microsoft Excel”

get left position of cell 1 of row 2 of active sheet of active workbook

→ 0.0

get top of cell 1 of row 2 of active sheet of active workbook

→ 34.0

get width of cell 1 of row 2 of active sheet of active workbook

→ 83.0

get height of cell 1 of row 2 of active sheet of active workbook

→ 130.0

end tell

(0.0, 34.0)

tell application “Script Editor”

choose file

alias “MG_Archive:thumbnails:DSCF2113.JPG”

end tell

tell application “Microsoft Excel”

activate

make new shape at beginning of active sheet of active workbook

shape “Shape_7” of active sheet of active workbook

set width of shape “Shape_7” of active sheet of active workbook to 100.0

set height of shape “Shape_7” of active sheet of active workbook to 66.0

set top of shape “Shape_7” of active sheet of active workbook to 34.0

set left position of shape “Shape_7” of active sheet of active workbook to 0.0

user picture shape “Shape_7” of active sheet of active workbook picture file “/Volumes/MG_Archive/thumbnails/DSCF2113.JPG”

error number -50

Result:

error “Microsoft Excel got an error: Parameter error.” number -50

I made an external drive and same name of each folder and image file.
This test drive caused same error, though I don’t understand the reason.

I had a test with PNG image in my pictures folder within internal SSD.

Here’s a new version. This works for me with test drive environment.

–New Version
http://piyocast.com/as/archives/16978

Next time, I want you to write your script by yourself.

Come on Piyomaru you cn do this…

tell current application

offset of “C” in “ABCDEFGHIJKLMNOPQRSTUVWXYZ”

→ 3

(3, 5)

end tell

tell application “Microsoft Excel”

get left position of cell 3 of row 5 of active sheet of active workbook

→ 130.0

get top of cell 3 of row 5 of active sheet of active workbook

→ 64.0

get width of cell 3 of row 5 of active sheet of active workbook

→ 65.0

get height of cell 3 of row 5 of active sheet of active workbook

→ 16.0

end tell

(130.0, 64.0)

tell application “Script Editor”

choose file

alias “MG_Archive:thumbnails:DSCF2113.JPG”

end tell

tell application “Microsoft Excel”

activate

make new picture at beginning of active sheet of active workbook with properties {file name:“/Volumes/MG_Archive/thumbnails/DSCF2113.JPG”, height:66.0, width:100.0, top:64.0, left position:130.0}

error number -1708

Result:

error “Microsoft Excel got an error: Can’t make class picture.” number -2710 from picture to class

I had some test with same drive path data and image format and has no error.
I suspect your JPEG image is broken.
Try other image data.

The script will work if the particular picture has been imported before using Excel’s “Insert/Picture…” menu item.
If not done b4 → error
don’t know why !

What’s your machine?
Which version of macOS?

Sonoma 14.5
Macbook pro M1

Your paths look inconsistent.

The result of your choose file command seems to be on the startup disk.
--> alias "MG_Archive:thumbnails:DSCF2113.JPG"

But in your make command, you specify a file on an external drive.

Excel’s own ‘insert picture’ results in a proper, functioning path.

Also, your command is make new picture. I don’t think that means anything, hence the error.

This works but only places the image as a floating image on top, I want the image in the Cell…

set newPic to make new picture at beginning of worksheet 1 of workbook 1 with properties {file name:POSIX file (item (idx) of thumbnailRefLinkList), height:targetImageHeight, width:targetImageWidth, top:theTop, left position:theLeft, placement:placement move}

I don’t think you can do that.

That said, by making ‘worksheet 1’ the destination, you likely preclude it from putting the image inside a cell.

Try using something like cell "C3" of worksheet 1 etc…

I made a test with 30 x 30 cells to place image each.
No error occured.

You should use “B4” instead of “b4”. Small alphabet characters are not acceptable in this script.

I think the operation is not acceptable for Microsoft Excel.

By the way, Apple Numbers can store image in each cell.

Hi Piyomaru - can you send me a Excel spreadsheet with an embedded image in it

http://piyocast.com/as/wp-content/uploads/2024/12/TestWorkbook.xlsx.zip

This is it.

Apologies I meant “before” by b4, and not cell “b4”

Its strange that if the picture has been inserted from excel menu → insert, it can be inserted by script again. But not a new image

Does Script Editor or Script Debugger has Full Disk Access permission?