Applescript and Office Word 2008

M

massimuccio007

Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel i've got a word file .... with a non uniform table in it in which i need to write some text.......(by non uniform i mean that i've got more than one table nested one into another , that the table isn't square shaped and it's not possible to identify the cell in which i need to write into by column or row number) (At least for me)....
how am i supposed to accomplish such task with office 2008 and applescript??

thanx
 
P

Peter Jamieson

Before even attempting to look at this in any depth: how will you
identify the cell? - e.g. will it be identified by the current
selection? Or are you asking us how you might "mark" the cell so that
applescript can stuff the text you want in the right place?

Peter Jamieson

http://tips.pjmsn.me.uk
 
M

massimuccio007

Hi Peter, thank you very much for your reply...
to be honest i managed to find a way to achieve what i wanted ... (by writing something in that cell ...and by using the command find and replace with applescript).... but the boudt still remains.... hence i'd still be glad to know if there's a way ... both with the current selection and by "marking" that determined cell...
thank you again, Max
 
P

Peter Jamieson

to be honest i managed to find a way to achieve what i wanted ... (by

Well done!

I wish this group had a resident AppleScript expert because I still find
working out how to do things in Applescript very hard.

But one really simple way is:

tell application "Microsoft Word"
tell selection
type text text "mytext"
end tell
end tell


Peter Jamieson

http://tips.pjmsn.me.uk
 
P

Peter Jamieson

Another approach you can use is to put a bookmark in the cell you want
to modify and use script like this:

tell application "Microsoft Word"
set bmRange to text object of bookmark "myBookmark" of active document
set bmStart to bmRange's start of content
set content of bmRange to "Inserted Text"
set bmEnd to bmStart + (count "Inserted Text")

make new bookmark at active document with properties ¬
{name:"myBookmark", start of bookmark:bmStart, end of bookmark:bmEnd}
end tell

This came one of the most useful starting points I have found,
especially if you are reasonably familiar with automating Word from VBA.

http://www.mactech.com/vba-transition-guide/index-041.html

Peter Jamieson

http://tips.pjmsn.me.uk
 
M

mdh

Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel i've got a word file .... with a non uniform table in it in which i need to write some text.......(by non uniform i mean that i've got more than one table nested one into another , that the table isn't square shaped and it's not possible to identify the cell in which i need to write into by column or row number) (At least for me)....

By "not possible to identify the cell", do you mean that there isn't a
systematic way to describe it, or that it is hard to express this in a
way that applescript will handle it?

If the former, scripting will be hard and it is best to encode the
significance of the cells in the document template (like you did with
the search/replace approach).

if the latter, then some ideas for playing with Applescript:

1) get the Word 2004 Applescript reference guide:
http://download.microsoft.com/downl...-B252-F09C465CE29C/Word2004AppleScriptRef.pdf
2) check out Microsoft's online info for scripting in 2008:
http://www.microsoft.com/mac/developers/default.mspx
3) Run simple test scripts to understand the document structure.
E.g.:

Create a new document, and insert a 5x2 table in it. Fill the cells.
In 2nd cell of row 2, paste in a 2x2 table (to give you the nested
tables)

The first table is directly accessed as "table 1 of active document",
and you can get some idea of the nested table with:

tell application "Microsoft Word" to get properties of cell 2 of row 2
of table 1 of active document
and
tell application "Microsoft Word" to get tables of cell 2 of row 2 of
table 1 of active document

You might then try something like:
tell application "Microsoft Word"
set myCell to cell 2 of row 2 of table 1 of active document
get content of text object of (cell 2 of row 1 of (table 1 of
myCell))
end tell

Matt
 

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

Top