Title: Re: Script to print envelopes in Word from Entourage
This is a GREAT!!!!!!!!!!!  script. I just compiled and ran it. Thanks George!


Roger


(Sorry for the use of HTML, but I wanted to be sure the following script came through without spurious line breaks.)

Several people have mentioned that they’d like to be able to print an envelope from Entourage. Well, that’s what this script does. After you’ve saved this as a compiled script from Script Editor in your Entourage scripts folder, the next step is to select a contact in your address book. Don’t open the contact; just select it.

Then run this script from the Script Menu. You’ll be asked if you want to use the Home or Work address of the selected contact (if the address is missing vital information, you’ll be told about that), and you’re also asked if you want to include a barcode.

Then Word is launched to create/print an envelope.

Enjoy!

George
(The script is provided as a public service; there are no warranties!)


tell
application "Microsoft Entourage"
    
    try
       set cnt to selection
        if cnt is "" or cnt is {} then
           beep
            return
       end if
   on error
       beep
        return
   end try
   
    set cnt to item 1 of cnt
    
    if class of cnt is not contact then
       display dialog ¬
            "Please select a contact in your address book" buttons "Okay" default button "Okay"
        return
   end if
   
    set l to (button returned of (display dialog ¬
        "Use Home or Work address?" buttons {"Home", "Work", "Cancel"} ¬
        default button "Home"))
    
    if l is "Cancel" then
       return
   else if l is "Home" then
       set a to home address of cnt
    else
       set a to business address of cnt
    end if
   
    set n to first name of cnt & " " & last name of cnt
    set s1 to street address of a
    set s2 to street address 2 of a
    set c to city of a
    set s to state of a
    set z to zip of a
    
end tell

if (s1 is "" and s2 is "") or (c is "") or (s is "") or (z is "") then
   display dialog "This contact does not have a valid " & l & ¬
        " address" buttons {"Okay"} default button "Okay"
    return
end
if

set b to (button returned of (display dialog ¬
    "Do you want to print a barcode?" buttons {"Yes", "No"} default button "No"))

set csz to c & ", " & s & "  " & z

set m to "recep = " & AddQuotes(n) & " & vbCr & "

if s1 is not "" then
   set m to m & AddQuotes(s1) & " & vbCr & "
end if

if s2 is not "" then
   set m to m & AddQuotes(s2) & " & vbCr & "
end if

set m to m & AddQuotes(csz) & return
set m to m & "retaddr = Application.UserName & vbCr & Application.UserAddress"
set m to m & return & "ActiveDocument.Envelope.PrintOut Address:=recep, ReturnAddress:=retaddr, Size:=\"Size 10\""

if b is "Yes" then
   set m to m & ", PrintBarCode:=True"
end if

tell application "Microsoft Word"
    activate
    try
       get document 1
    on error
       make new document
    end try
   do Visual Basic m
end tell

on AddQuotes(theString)
    set theString to "\"" & theString & "\""
    return theString
end AddQuotes





Reply via email to