Applescript - Excel inserting a image with URL Hyperlink

Hi,

I’m trying to create a Applescript that will allow me to insert images into specific locations within Excel and have that image be a clickable image that points to a specific website or URL address. I’ve figured out how to automate the inserting of the image into Excel, but don’t know how to associate a URL or hyperlink for that image. I know how to do it manually within Excel. If I right click on an image in Excel and select Hyperlink, I can manually input a URL for that particular image in the “Link to:” field and I am then able to click on that image and it will open up my default browser and take me to that website. Can anyone help me code the piece to put in the URL automatically? Here’s my script so far

Thanks,
Ezmeralda

set mypath to (path to me as string)
set AppleScript’s text item delimiters to “:”
set theFolder to (text 1 thru text item -2 of mypath) & “:” as Unicode text
set imageFile to theFolder & “image1.jpg”

tell application “Microsoft Excel”
set imageHeight to 140
set imageWidth to 280
set theLeft to left position of cell “H29”
set theTop to top of cell “H29”

set newPic to make new picture at beginning of worksheet 1 of workbook 1 with properties {file name:(imageFile as text), height:imageHeight, width:imageWidth, left position:theLeft, top:theTop}

end tell

Inserting the URL to the image and inserting the image itself in worksheet is different things.

First, inserting the image itself:


set imageFile to choose file
tell application "System Events" to set imageFile to URL of imageFile

tell application "Microsoft Excel"
	activate
	set myWorkbook to active workbook
	tell myWorkbook to tell worksheet 1
		set imageHeight to 140
		set imageWidth to 280
		set theLeft to left position of cell 1 of column "$A:$A"
		set theTop to top of cell 1 of column "$A:$A"
		set newPic to make new picture at beginning with properties {file name:imageFile, height:imageHeight, width:imageWidth, left position:theLeft, top:theTop}
	end tell
end tell

And now, inserting the URL to image:


tell application "Microsoft Excel"
	activate
	set myWorkbook to active workbook
	tell myWorkbook to tell worksheet 1
		make new hyperlink of cell 1 of column "$A:$A" with properties {address:"https://funkyimg.com/view/2W4Jc", text to display:"Remote IMAGE"}
	end tell
end tell

NOTE: You should have opened some Excel document before the running of the scripts above.