Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with Applescript PASTE function in MS Word

43 views
Skip to first unread message

Debra Clinton

unread,
Apr 27, 2005, 2:24:56 PM4/27/05
to
Has Applescript completely changed in OS X 10.3?

I recently switched to OSX 10.3 and am now having problems with my
Applescripts - where I previously was able to use a script to copy text from
Filemaker Pro and paste it into MS Word, I now get one of two messages...

1. The variable paste is not defined (Error -2753) OR
2. Microsoft Word got an error: canąt continue <event MSWDactv> (Error
­1708)

My applescripts looks like this:

tell application "Finder"
activate
select file "e-Letterhead.doc"
open selection
end tell
tell application "Microsoft Word"
paste
end tell

AND

tell application "Finder"
activate
select file "e-Letterhead.doc"
open selection
end tell
tell application "Microsoft Word"
activate
do Visual Basic "Selection.MoveDown Unit:=wdScreen, Count:=1"
do Visual Basic "Selection.EndKey Unit:=wdLine"
paste clipboard
end tell

It also seems to have screwed up for those using it on OS 9.2...

Iąve run out of options at the Apple and Filemaker sites... So any help
would be greatly appreciated!

Thanks!
------------------------------------
Debra Clinton
Cambridge Management Planning Inc.
Tel. 416-484-8408 Fax: 416-484-0151
<dcli...@cambridgemgmt.com>
------------------------------------

Paul Berkowitz

unread,
Apr 27, 2005, 3:33:58 PM4/27/05
to
You need to tell us which version of Word you are using now. AppleScript for
OS 10.3 has hardly changed, although there are a few differences from OS 9,
including in the Finder.

But Word 2004's AppleScript has completely changed from what existed for
previous versions. 'paste' is no longer a command, so it would compile as a
variable and error, if you had copied the text from your previous script and
tried to compile it again in Script Editor. (O the other hand, if you had
opened your previous script now in the OS X Script Editor you wouldn't see
'paste', you'd see «event miscpast». So you must have tried to re-write it,
and it won't work that way. On the other hand, the second error you show
("Can't continue «event MSWDactv»") must be from the second script and
indicates you _haven't_ recompiled it: if you had 'activate' would now
compiled again but you'd get another error for 'paste clipboard'. I'm going
to assume that you must have Word 2004 now.

I'm a little confused because I don't see anything about FileMaker Pro, and
I'm wondering how you can open a file in the Finder like that when you don't
have a proper file-path. The file won't open in the Finder without a
file-path and you'd frankly be better off asking Word to open the file
anyway.

If you'd like to explain what the Finder part is doing I'll show you a
better way that doesn't involve selecting anything. The 'paste' and 'paste
clipboard' part of each script can be replaced by

paste object

That should not error, but it's possible that Word is using a different
clipboard than what you used to copy in FMP and you may not get what you
expect. There will be other ways to do it in that case.

Just re-type

activate

in the second script and you won't get that second error.

The do Visual Basic lines can bow be replaced by real AppleScript,. but they
should work OK as is. Although I'm not 100% certain of EndKey. If that
errors, there will be another way to do it.

--
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.


> From: Debra Clinton <dcli...@cambridgemgmt.com>
> Newsgroups: microsoft.public.mac.office.word
> Date: Wed, 27 Apr 2005 14:24:56 -0400
> Subject: Problem with Applescript PASTE function in MS Word
>
> Has Applescript completely changed in OS X 10.3?
>
> I recently switched to OSX 10.3 and am now having problems with my
> Applescripts - where I previously was able to use a script to copy text from
> Filemaker Pro and paste it into MS Word, I now get one of two messages...
>
> 1. The variable paste is not defined (Error -2753) OR

> 2. Microsoft Word got an error: can¹t continue <event MSWDactv> (Error


> ­1708)
>
> My applescripts looks like this:
>
> tell application "Finder"
> activate
> select file "e-Letterhead.doc"
> open selection
> end tell
> tell application "Microsoft Word"
> paste
> end tell
>
> AND
>
> tell application "Finder"
> activate
> select file "e-Letterhead.doc"
> open selection
> end tell
> tell application "Microsoft Word"
> activate
> do Visual Basic "Selection.MoveDown Unit:=wdScreen, Count:=1"
> do Visual Basic "Selection.EndKey Unit:=wdLine"
> paste clipboard
> end tell
>
> It also seems to have screwed up for those using it on OS 9.2...
>

> I¹ve run out of options at the Apple and Filemaker sites... So any help

Micheal

unread,
May 5, 2005, 1:25:49 AM5/5/05
to
Hi,

I believe this is an old script of yours that I have been using,

Print MultiEnvelope based on
Print MultiEnvelope from E in W, v 1.0
Copyright © 2000 George Clark <mailto:gac...@sprynet.com>
Some portions inspired by/altered due to input from Omar Shahine and
David Cortright

It has been great in Office 2001 and X, but now I get an error in
Office 2004.

When it runs, it stops and says:

Microsoft Word got an error: Can't continue «event MSWDactv».

In the script it says, twice, something about MSWDactv


tell application "Microsoft Word"
«event MSWDactv»
make new document
end tell

tell application "Microsoft Word"
«event MSWDactv»
do Visual Basic vbScript
end tell

I'm assuming that the new 2004 doesn't understand MSWDactv anymore.
What should I change it to? I'm not sure what it means to start with
and I can't locate the former Applescript dictionary for MSWord to look
it up. And I'm not very familiar with Applescript to be certain that
is the problem. Can you help me out?

I'm running Office 2004 with Mac OS 10.3.9 and below i have pasted the
entire script.

----------------------------------------

property useBarcode : "Yes"
property useTitle : "No"
property useSuffix : "No"
property useJobTitle : "No"

(*
Valid settings for the above four properties are "Yes", or anything
else. If "Yes"
the item is included on the envelope. If anything else, it is not
included
*)

property returnAddress : "Ask"
property deliveryAddress : "Ask"

(*
Valid settings for the above two items are "Ask", "Default" or "Work".
"Ask" will
ask each time you run the script which address to use for your return
address, or
for the delivery address (respectively). If set to "Default", whatever
is the
default address is used. When set to "Work", the Work address is always
used. Any
other setting will force the use of the Home address
*)

global userAddress
global userCountry
global counter
set counter to 0

tell application "Microsoft Entourage"

activate
try
set theSelection to selection
set temp to item 1 of theSelection
on error
my Error_Message()
return
end try

if class of temp is not contact and class of temp is not group then
my Error_Message()
return
else if deliveryAddress is "Ask" then
set addchoice to (button returned of (display dialog ¬
"Use Default, Home or Work address of the contact?" buttons
{"Default", "Home", "Work"} ¬
default button "Default"))
else
set addchoice to deliveryAddress
end if

if returnAddress is "Ask" then
set rtnAdd to (button returned of (display dialog ¬
"Use your Home or Work address as the Return Address?" buttons
{"Home", "Work"} ¬
default button (default postal address of me contact as string)))
else if returnAddress is "Default" then
set rtnAdd to (default postal address of me contact as string)
else
set rtnAdd to returnAddress
end if

if rtnAdd is "Work" then
set rtnAdd to business address of me contact
set userDept to department of me contact
set userCompany to company of me contact
else
set rtnAdd to home address of me contact
set userDept to ""
set userCompany to ""
end if

set userAddress to (first name of me contact) & " " & (last name of me
contact) & return
if userDept is not "" then set userAddress to userAddress & userDept &
return
if userCompany is not "" then set userAddress to userAddress &
userCompany & return
set userAddress to userAddress & street address of rtnAdd & return
set userAddress to userAddress & city of rtnAdd

if (state of rtnAdd) is not "" then
set userAddress to userAddress & ", " & state of rtnAdd
end if

if (zip of rtnAdd) is not "" then
set userAddress to userAddress & " " & zip of rtnAdd
end if
set userCountry to country of rtnAdd

end tell

tell application "Microsoft Word"
«event MSWDactv»
make new document
end tell

tell application "Microsoft Entourage"

repeat with theItem in theSelection

if class of theItem is contact then

if addchoice is "Default" then
set thisadd to (default postal address of theItem as string)
else
set thisadd to addchoice
end if

my Process_Contact(theItem, thisadd)

else if class of theItem is group then

set grouplist to every group entry of theItem

repeat with gmember in grouplist
set temp to (address of content) of gmember
set theContact to find temp
if theContact is not {} then
set theContact to item 1 of theContact
if addchoice is "Default" then
set thisadd to (default postal address of theContact as string)
else
set thisadd to addchoice
end if
my Process_Contact(theContact, thisadd)
end if
end repeat

end if

end repeat

end tell

tell application "Microsoft Word" to close front document without
saving

tell application "Microsoft Entourage"
activate
if counter = 0 then
display dialog ¬
"No envelopes were printed because no valid addresses were found"
buttons {"Okay"} default button "Okay"
end if
end tell

on Process_Contact(whichc, whicha)

global counter

tell application "Microsoft Entourage"

set theName to first name of whichc
set temp to last name of whichc
if temp is not "" then
if theName is "" then
set theName to temp
else
set theName to theName & " " & temp
end if
end if

if theName is not "" then

set jobTitle to ""

if whicha is "home" then
set a to home address of whichc
set dept to ""
set co to ""
else
set a to business address of whichc
set dept to department of whichc
set co to company of whichc
if useJobTitle is "Yes" then set jobTitle to job title of whichc
end if

set theStreetAddress to street address of a
set theCity to city of a

if theStreetAddress is not "" and theCity is not "" then

set theState to state of a
set theZip to zip of a
set theCountry to country of a

if useTitle is "Yes" then
set temp to title of whichc
if temp is not "" then set theName to temp & " " & theName
end if

if useSuffix is "Yes" then
set temp to suffix of whichc
if temp is not "" then set theName to theName & ", " & temp
end if

end if

else
set theStreetAddress to ""
set theCity to ""
end if

end tell

if theStreetAddress is not "" and theCity is not "" then

set counter to counter + 1

set tempReturn to userAddress

if jobTitle is not "" then set theName to theName & ", " & jobTitle

set theAddress to theName & return

if dept is not "" then set theAddress to theAddress & dept & return
if co is not "" then set theAddress to theAddress & co & return
set theAddress to theAddress & theStreetAddress & return
set theAddress to theAddress & theCity
if theState is not "" then set theAddress to theAddress & ", " &
theState
if theZip is not "" then set theAddress to theAddress & " " & theZip
if theCountry is not "" then
if theCountry ≠ userCountry then
set theAddress to theAddress & return & theCountry
set tempReturn to tempReturn & return & userCountry
end if
end if

set vbScript to "recep = " & my Process_for_VB(theAddress)
set vbScript to vbScript & "retaddr = " & my
Process_for_VB(tempReturn)
set vbScript to vbScript & "ActiveDocument.Envelope.PrintOut
Address:=recep, _
ReturnAddress:=retaddr, PrintBarCode:="
if useBarcode is "Yes" then
set vbScript to vbScript & "True"
else
set vbScript to vbScript & "False"
end if

tell application "Microsoft Word"
«event MSWDactv»
do Visual Basic vbScript
end tell

end if

end Process_Contact

on Process_for_VB(theString)
set i to 0
set finalString to ""

repeat
set i to i + 1
try
set temp to paragraph i of theString
set temp1 to "\"" & temp & "\""
set finalString to finalString & temp1

if temp = paragraph -1 of theString then
set finalString to finalString & return
else
set finalString to finalString & " & vbCr & "
end if
on error
exit repeat
end try
end repeat
return finalString
end Process_for_VB

on Error_Message()
tell application "Microsoft Entourage"
display dialog ¬
"Please select one or more contacts or groups in your address book"
buttons {"Okay"} default button "Okay"
end tell
end Error_Message

Paul Berkowitz

unread,
May 7, 2005, 2:18:02 AM5/7/05
to
On 5/4/05 10:25 PM, in article
1115270749....@f14g2000cwb.googlegroups.com, "Micheal"
<micm...@pacbell.net> wrote:

>
> I believe this is an old script of yours that I have been using,

An old script of whose? it says right there "Copyright George Clark" and
gives his email address. George has not been in these newsgroups for a few
years now. I did have my own script that did something similar - Print
Envelopes, that came in Office for Office.


>
> Print MultiEnvelope based on
> Print MultiEnvelope from E in W, v 1.0
> Copyright © 2000 George Clark <mailto:gac...@sprynet.com>
> Some portions inspired by/altered due to input from Omar Shahine and
> David Cortright
>
> It has been great in Office 2001 and X, but now I get an error in
> Office 2004.

All of AppleScript has changed in 2004. All the raw codes have changed. Most
of the script would be in 'do Visual Basic' which has not changed, but some
of it you'll see just as «raw codes» which no longer function in Word 2004.

Although it could probably be adapted, with a lot of effort (opened with
Word 2001 or X open, or as you did on Classic Script Editor with Word 2001
available), then save a copy as Text. Open the text script file with Word
2004 around. If the one and only problem line is

«event MSWDactv»

don't go through all that - just change that line, wherever it comes as

activate

But there's no need for this script in Word X or 2004. Word X and 2004 have
a functioning "Query" button at the bottom of the Data Merge Manager that
lets you choose selected contacts, or by category, or a mix of that. And
fields you can assemble in the envelope layout that will offer you almost as
many choices as the script, more freedom of layout and punctuation, and much
quicker to set up.

The only reason for George's and my scripts was to fill the gap left by a
dimmed-out Query button in the then-new Data Merge Manager in Word 2001.

Micheal

unread,
May 7, 2005, 4:28:50 PM5/7/05
to
Thanks, it almost got me there, but then I ran into another error with
Visual Basic. I hadn't known about the change in MS Word, but it still
doesn't work for me. I have many couples in my entrourage with
different last names, but that I keep together. I had originally
gotten the script from George Clark on this or another board, then
later I got your update. (It has been awhile and I can't remember the
exact line of events, hence I inculded the copywrite line) I have
modified it so that it addresses the envelope using both last names, or
another script to address it to just the person or to just their
spouse. MS Word still can't do this name swapping for me.

Anyhow, I made the change, but then the MS Visual Basic debugger opened
with this error. The first line had a yellow highlight and red arrow
next to it and the line "ActiveDocument....." was highlighted with the
system highlight. I'm completley clueless on even reading what this
means. I have put **** in the name and addresses that it showed. Can
you help me out with this.

Sub TmpDDE()
recep = "************" & vbCr & "********************" & vbCr & _
"*************************"
retaddr = "***************" & vbCr & "**********************" &
vbCr & _
"*******************" & vbCr & "***********************"
ActiveDocument.Envelope.PrintOut Address:=recep, _ "& vbLf &"
ReturnAddress:= _
retaddr, PrintBarCode:=True
End Sub

Paul Berkowitz

unread,
May 8, 2005, 11:08:32 AM5/8/05
to
On 5/7/05 1:28 PM, in article
1115497729.9...@g14g2000cwa.googlegroups.com, "Micheal"
<micm...@pacbell.net> wrote:

Michael, I really can't sit here trying to debug a deprecated script that I
didn't write. (I can't recall editing George's script: I later wrote my own
"Print Envelopes" script which you can find in the Office for Office
package. But it too might have a few non-VB commands which need to be
changed for Word 2004.)

My guess would be that you opened the script in OS X's Script Editor and
recompiled and saved, so that the carriage returns within literal quoted
strings - which is what the entire 'do Visual Basic' command is (it's all in
"quotes") now contains Unix Linefeeds rather than Mac Carriage Returns, so
now the VB Editor is not seeing them as separate lines. You see where that

Address:=recep, _ "& vbLf &"

occurs? Nothing should be following the _ on the same line. The _ is a
continuation character at the end of a line, but the following carriage
return isn't there. Just possibly a little trick _might_ save it. If you
change that vbLf to vbCr it just might fix it. (George should not have used
vbLf anyway - it should have been vbCr - but it didn't really matter before.
Here it just might make the VB Editor happy, though I wouldn't hold out much
hope.

As I suggested last time, just learn to use the Data merge manager in Word
instead.

Micheal

unread,
May 9, 2005, 12:24:27 AM5/9/05
to
Thanks, I'm going to give your suggestion a try.

The problem with the Data merge manager is it will not print the custom
fields that I need to use. As far as I can tell anyway. Am I missing
something there? It would be easier to use the Data Merge Manager if I
could use any of the fields in Entourage. Again, thanks for your help,
I really appreciate it.

0 new messages