Re: Word scripting?
Re: Word scripting?
- Subject: Re: Word scripting?
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 24 Mar 2003 10:14:40 -0800
On 3/23/03 1:29 PM, "Dave Groover" <email@hidden> wrote:
>
Can someone enlighten me as to how I can or should, improve my Word
>
script? If someone can show me an example of one already done, so
>
much the better. Here is what I have and the minimum I would like
>
help with:
>
>
tell application "Microsoft Word"
>
make new document
>
make new line at window 1 with data AddressOnClipboard
>
set justification of line 5 to right
>
end tell
>
>
This is to write a letter from a contacts record in my DB.
>
I have a block of address data that is parsed to the AS from my DB
>
(Panorama). It includes the current date and a dear (first name) and
>
an ending. I could also get the Word app to insert the proper date
>
and header pieces but so far my Word app is not responding to the Do
>
script examples as shown in the Danny Goodman book. And in the short
>
run, it is easier to at least throw the data into the blank page pre
>
arranged. The problem however is that after I set the date to include
>
my closing, I want to move the insertion point back up to where I
>
want to start the letter (the body).
>
>
I am not finding how to move the insertion point, as a cursor only,
>
to the point where I want to start my typing of the letter. Can
>
someone suggest the correct phrase for this?
The scripting of Word is notoriously unreliable precisely for things like
this. It starts out OK, once you get your head around its 'text from 12 to
25' terminology, but then it goes all wrong. This is likely because Word is
not a text editor but a complex word processor, and has lots and lots of
invisible characters which control paragraph style, etc. It was never
properly translated for AppleScript, and probably can't be in the simple
text-editor way we'd like. Sooner or later you crash. It's not worth it.
The way to do it, for now, is by using 'do Visual Basic', which lets you do
VBA from AppleScript. If you get my script "Address Word Letter" or Address
Word Letter X" at
AppleScript Central <
http://www.applescriptcentral.com/>
you'll see precisely how to move an insertion point. For general
instructions on how to use 'do Visual Basic', see
http://www.mvps.org/word/FAQs/WordMac/WordAppleScript.htm
To find the VBA terminology for a particular Word function, go to
Tools/Macro/Visual Basic Editor/Help/Word VB Contents (or Search). It's an
excellent Help Guide.
It's unfortunate that you have to learn another language (VBA) to script
Word reliably, but it's the only way that works at the moment. Once you get
into it, you'll see how incredibly powerful it is: it controls the whole
complex object model, not just simple text editing. There is some hope that
MS may be revising Word AppleScript for a future version.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.