Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript Insert picture into word table cell?

How is it done?


I have a cell that I wish to insert a picture from the HD int but I just can't seem to get it to work... I have no problem inserting the picture at the end of the document but not in the cell... thoughts?


Works:


make new inline picture at end of proposal with properties {file name:"Macintosh HD:Users:User:Misc:pict.jpg", save with document:true}


Does not work:

make new inline picture at (get cell from table proposalTable row 3 column 3) with properties {file name:"Macintosh HD:Users:User:Misc:pict.jpg", save with document:true}


thanks!
-J

Posted on May 9, 2011 3:36 PM

Reply
17 replies

May 11, 2011 9:54 AM in response to remmingtonShowdown

Hi,


Here is an example


----

settfileto"Macintosh HD:Users:User:Misc:pict.jpg"

tellapplication"Microsoft Word"


tellactive document


setxtotext objectofcell3ofrow3oftable1


-- set content of x to "" -- empty the cell



-- insert picture in a empty cell or before the text in the cell


makenewinline pictureatbeforexwith properties{file name:tfile,save with document:true}


endtell

endtell

-------

Apr 15, 2015 11:34 AM in response to remmingtonShowdown

Hi everyone,


Sorry for bringing the old threads out but I'm currently trying to use Jacques's script but to no avail... Trying to insert a picture before a word in a cell.


I tried this script and some others that I found around the internet but nothing seemed to fix the problem.


I started Applescript on Monday so not really good at it yet.


Thanks a lot for your help !


R.

Apr 16, 2015 11:32 AM in response to remmingtonShowdown

Thanks for your response but I really think I'm a bit thick...


tell application "Microsoft Word"

activate

open "MyWordFile"



set tfile to "MyImagePath"

tell application "Microsoft Word"

tell active document

set x to text object of cell 3 of row 3 of table 1

makenewinline pictureat before xwith properties {file name:(tfile as string), save with document:true}

end tell

end tell

end tell

The error I get is "it is impossible to create the class "inline picture"

Apr 16, 2015 2:20 PM in response to Raphnouf

Let say the internal drive of your Mac is named Macintosh hd.

At the first level of the drive, you have your Word document named table template.docx

Then, there is a folder named images containing the file you want to import.

This file is named big Logo.jpg

You have to refer to those 2 docs like this:

Set tfile to "Macintosh hd:images:big Logo.jpg"

set wfile to "macintosh hd:table template.docx"

And the rest of your script will be:

tell application "Microsoft Word"

activate

open wfile

tell active document

set x to text object of cell 3 of row 3 of table 1

makenewinline pictureat before xwith properties {file name:(tfile as string), save with document:true}

end tell

end tell

😉

Apr 17, 2015 2:18 AM in response to ionah

I used your script but still got the same old message:

Microsoft Word got an error: Can’t make class picture. "number -2710 from inline picture to class" 😐

No clue if it might be the problem but maybe word 2013 runs differently.

I have a question though, What does "set x to text object of cell 1 of row 1 of table 1" refer to?

Apr 17, 2015 11:26 AM in response to ionah

Word 2011, my bad :/


Here is the script, with the right paths :

set tfile to "/Users/macbookpro/Pictures/QRCode www.pps4Me.de.png"

set wfile to "/Users/macbookpro/Documents/Scripts/Labels/Frame.docx"

tell application "Microsoft Word"

activate

openwfile

tell active document

set x to text object of cell 1 of row 1 of table 1

makenewinline pictureat before xwith properties {file name:(tfile as string), save with document:true}

end tell

end tell

The cells will be filled with one word each time. The images should appear before the text.

And here is an image of the word table : User uploaded file

Thanks a lot for trying to solve the problem by the way, I really appreciate 🙂

Apr 17, 2015 1:42 PM in response to Raphnouf

The script Jacques gives to you is right.

It does exactely what you want.


You just need to learn how Applescript refers to files.

I tried to give you an example in my last post.

You cannot use slashes. (They are reserved for unix paths).

File description must be written with semi-colons (:), starting with the volume (or drive), then descending the hierachy of folders and subfolders containing the file, finishing by the file itself, of course.

Try to drag and drop your files on the script window, you should obtain the right syntax for their paths.


😉

Applescript Insert picture into word table cell?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.