VB/Applescript solution for populating a table

J

Joe

I have a document that has nothing but a single, 200+ row, 3 column
table. Each cell contains a string and I need a script that
1. goes to the first cell,
2. reads the string into a variable theString,
3. send the string and gets the result using a one-liner applescript
call to another app:
tell app "MyApp" to set theResult to «event thisEvent» {"Home",
theString, true}
4. places the result into that same cell (either replacing the current
string, or after a carriage return would be acceptable)
5. moves to the next cell, repeating till the end.

It doesn't matter to me whether I'd do this using a VB script that
contains a single Applescript call or using the new, jam-packed
dictionary of Word 2004 (which I've not spent anytime looking at yet)
and accomplishing the whole thing in Applescript.
(I am alot more familiar with Applescript, but like to learn both.)

Any help or suggestion of a better group to ask in?
 
J

Joe

If noone here does VBA and Applescript, is there a better group to ask
in?
Thanks for any help.
Joe
 
B

Beth Rosengard

Hi Joe,

There are folks here who do both. Give it another day or two and you should
get an answer.

Beth
 
P

Paul Berkowitz

I have a document that has nothing but a single, 200+ row, 3 column
table. Each cell contains a string and I need a script that
1. goes to the first cell,
2. reads the string into a variable theString,
3. send the string and gets the result using a one-liner applescript
call to another app:
tell app "MyApp" to set theResult to «event thisEvent» {"Home",
theString, true}
4. places the result into that same cell (either replacing the current
string, or after a carriage return would be acceptable)
5. moves to the next cell, repeating till the end.

It doesn't matter to me whether I'd do this using a VB script that
contains a single Applescript call or using the new, jam-packed
dictionary of Word 2004 (which I've not spent anytime looking at yet)
and accomplishing the whole thing in Applescript.
(I am alot more familiar with Applescript, but like to learn both.)

Well, you ought to learn Word AppleScript then. You can get the 500+-page
Word AppleScript Reference (and also one for Excel and PPT) at MacTopia
website / Resources/Developers/AppleScript. Read up on text ranges in
particular in the introductory section.

I certainly hope that this pretend-code you're giving us for your other app:

tell app "MyApp" to set theResult to «event thisEvent» {"Home",
theString, true}


actually works and doesn't cause snarlups.

You also haven't said what you mean by "the next cell": moving along each
row from column 1 to 3, then the next row, or moving down the first column,
then the secoind, etc. It's _much_ easier to do it the first way (in both
AppleScript and VBA) because, unlike Excel sheets, cell is only an element
of row, not of column. This works: I tested with a version that simply added
a character "1" to the original string, then replaced it in the table.

Note two things:

1. The script has to remove the final two characters of the extracted
string, namely a carriage return and an invisible end-of-cell character
(returned as "BELL" - ASCII character 7), but doesn't need to re-insert them
in the replacement - they're done automatically by Word.
2. Word actually returns Unicode text, not plain ASCII strings. If your
other app can't cope with Unicode, you could try 'as string' before sending
theString over there. If theString really does have true Unicode characters,
however, that might not be enough for your app. You may need a rather exotic
handler for converting it to real plain text. Come back and ask if so.


tell application "Microsoft Word"
set theTable to table 1 of active document
set rr to (count rows of theTable)
set cc to (count columns of theTable)

repeat with i from 1 to rr
set theRow to row i of theTable
repeat with j from 1 to cc
set theString to content of text object of cell j of theRow
try
set theString to text 1 thru -3 of theString -- remove
"BELL" & carriage return at end
on error --if blank
set theString to ""
end try
--set theResult to theString & "1"
tell app "MyApp" to set theResult to «event thisEvent» {"Home",
theString, true}
set content of text object of cell j of theRow to theResult
end repeat
end repeat

end tell


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 

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