Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > word 2008 script questions
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 11th March 10:32
g.miller
External User
 
Posts: 1
Default word 2008 script questions



hi, just about as amateur as it can get when it comes to applescript.
i was able to create a script that i used to call from a filemaker 7
database that took information from a record in the database, opened
word (version X), and basically inserted the information. all was
well until i upgraded to leopard, necessitating and upgrade to
filemaker 9 and word 2008. my old script used VBA and now im trying
to redo it using applescript.

ive been searching online, trying to piece things together but have
run into a snag that i cannot figure out.
so far i have....

tell application "FileMaker Pro"
tell layout "Create Estimate"
set mycontactaddress to cellValue of field "contact_address" of
current record
end tell
end tell
tell application "Finder"
open file "letterhead" of desktop
end tell
tell application "Microsoft Word"
activate
set myDoc to active document
set myAddressTable to make new table at myDoc with properties
{number of rows:1, number of columns:2}
set enable borders of border options of myAddressTable to false
set content of text object of (get cell from table myAddressTable
of myDoc row 1 column 1) to "Cell 1, 1"
end tell

There are two problems.
1. if i run the script with Word initially closed, i get the error
"Microsoft Word got an error: Can’t get active document." on the 'set
myDoc to active document' step.
if Word is active but there are no documents open, i get and error
"Microsoft Word got an error: Can’t make class table." on the 'set
myAddressTable to make new table...' step.
if Word is active and "letterhead" is open, then it doesn't produce an
error on either of those steps.
is the script getting ahead of itself (thats what it seems like). can
i get it to pause between steps?

2. i get the error "Microsoft Word got an error: myAddressTable of
active document doesn’t understand the get cell from table message."
on the 'set content of text object...' step.
ive tried deleting that line and replacing it with "set myAddressCell
to cell 1 of row 1 of myAddressTable of myDoc" only to get the error
"Microsoft Word got an error: The object you are trying to access does
not exist" with 'cell 1' being the highlighted object that the error
refers to.

all i am trying to do at this point is insert text into the first cell
in the table i created.
any help is appreciated. thanks.
  Reply With Quote


 


2 11th March 10:32
jolly roger
External User
 
Posts: 1
Default word 2008 script questions



In article
<c5d1a6b4-d5f8-4951-a3b2-a8af83429765@r66g2000hsg.googlegroups.com>,

Rather than doing this, I would suggest telling Microsoft Word to open
the document directly.

--
Please send all responses to the relevant news group rather than directly
to me, as E-mail sent to this address may be devoured by my very hungry
SPAM filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google Groups.
You'll need to use a real news reader if you want me to see your posts.

JR
  Reply With Quote


 


3 11th March 10:32
g.miller
External User
 
Posts: 1
Default word 2008 script questions


the file 'letterhead' of desktop is an alias to a locked word doc that
exists elsewhere. because this script will be used by different
users, i dont know how to reference it. even if i move the original
file to the desktop on each computer, the username is different and so
the name of the path is different.

tell application "Microsoft Word"
open alias ":Users:user1:desktop:testhead.doc"
will not work for 'user2' or 'user3'
  Reply With Quote
4 11th March 10:32
michelle steiner
External User
 
Posts: 1
Default word 2008 script questions


In article
<198e6c80-5c05-4121-b1ae-9e83797afbd4@z72g2000hsb.googlegroups.com>,


But this should:

tell application "Microsoft Word"
open alias ((path to desktop as text) & "testhead.doc")

--
Support the troops: Bring them home ASAP.
  Reply With Quote
5 11th March 10:32
jolly roger
External User
 
Posts: 1
Default word 2008 script questions


Yep - "path to" is an appropriate way to reference things in relative or
unknown full paths.

You can read all about the "path to" command in the Standard Additions
dictionary (File > Open Dictionary in Script Editor).

--
Please send all responses to the relevant news group rather than directly
to me, as E-mail sent to this address may be devoured by my very hungry
SPAM filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google Groups.
You'll need to use a real news reader if you want me to see your posts.

JR
  Reply With Quote
6 14th March 07:21
g.miller
External User
 
Posts: 1
Default word 2008 script questions


thanks, that works great, but im still getting the 2nd error...

2. i get the error "Microsoft Word got an error: myAddressTable of
active document doesn’t understand the get cell from table message."
on the 'set content of text object...' step.
ive tried deleting that line and replacing it with "set myAddressCell
to cell 1 of row 1 of myAddressTable of myDoc" only to get the error
"Microsoft Word got an error: The object you are trying to access does
not exist" with 'cell 1' being the highlighted object that the error
refers to.
  Reply With Quote
7 14th March 07:21
jolly roger
External User
 
Posts: 1
Default word 2008 script questions


In article
<93c4506e-ceb0-4445-a4d8-b4ce2fd482c5@j22g2000hsf.googlegroups.com>,

Try this on for size:

(Note: Usenet or your news reader may line wrap long lines in the script
below. You'll have to fix such line wraps manually, by deleting the
appropriate carriage returns, before the script will compile correctly
on your computer.)

-- begin script
tell application "Microsoft Word"
activate
set myDoc to make new document
set myAddressTable to make new table at myDoc with properties
{number of rows:1, number of columns:2}
set enable borders of myAddressTable's border options to false

repeat with col from 1 to 2
my SetCellContents(myAddressTable, 1, col, "row 1, column " &
col)
end repeat
end tell

on SetCellContents(myTable, myRow, myColumn, myContents)
tell application "Microsoft Word"
set myCell to get cell from table myTable row myRow column
myColumn
set myText to the text object of myCell
set myText's content to myContents
end tell
end SetCellContents
-- end script

--
Please send all responses to the relevant news group rather than directly
to me, as E-mail sent to this address may be devoured by my very hungry
SPAM filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google Groups.
You'll need to use a real news reader if you want me to see your posts.

JR
  Reply With Quote
8 14th March 07:21
michelle steiner
External User
 
Posts: 1
Default word 2008 script questions


In article
<93c4506e-ceb0-4445-a4d8-b4ce2fd482c5@j22g2000hsf.googlegroups.com>,


Sorry, but I can't help you there; I don't have Word.

--
Support the troops: Bring them home ASAP.
  Reply With Quote
9 14th March 07:21
g.miller
External User
 
Posts: 1
Default word 2008 script questions


thank you so much.

i think the problem was i was asking for row 1 column 1 of myDoc, when
i didnt need to reference myDoc at all...

this is what it should be. i was able to back into it using your
subroutine.

set content of text object of (get cell from table myAddressTable row
1 column 1) to "the text i was trying to put into the cell"
  Reply With Quote
10 14th March 07:21
jolly roger
External User
 
Posts: 1
Default word 2008 script questions


In article
<5e56cb44-7850-4633-a9ad-3cb480a70022@s50g2000hsb.googlegroups.com>,

I recommend using subroutines (called "handlers" in AppleScript
terminology) whenever possible. Doing so will help make your code
easier to update and more scalable over time.

--
Please send all responses to the relevant news group rather than directly
to me, as E-mail sent to this address may be devoured by my very hungry
SPAM filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google Groups.
You'll need to use a real news reader if you want me to see your posts.

JR
  Reply With Quote
Reply


Thread Tools
Display Modes




666