• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Excel2004, System Events & NSReceiverEvaluationScriptError
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Excel2004, System Events & NSReceiverEvaluationScriptError


  • Subject: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 16 Dec 2004 14:19:58 -0800

It works perfectly here once I make a few changes.

I found that I could do everything in Debugger mode, stepping through a line
at a time,  up until the last line (keystroke return). So I changed that to:

    click button "Save" of window 1

and now the whole thing worked perfectly, stepping through.

When I clicked "Run" in either AppleScript or Debugger mode, it errored on
the same line as you did. That indicated to me that the previous line had
probably not finished. SD is just too fast - or Excel is too slow when SD is
in the front. The Print dialog is really a system dialog that Excel has to
fetch. So I just added a 'delay 1' in two spots, before and after the PDF
button, and everything works. (Oddly enough if I omitted the second delay
the error was two more lines below on the last line. It just takes time for
windows to appear.) Add 'delay 1' after _every_ line if necessary.

tell application "Microsoft Excel"
    activate
end tell

tell application "System Events"
    tell process "Microsoft Excel"
        keystroke "p" using command down
        delay 1
        click button "Save As PDFŠ" of UI element 4 of window "Print"
        delay 1
        keystroke "d" using command down
        keystroke "My Desired Worksheet"
        click button "Save" of window 1
    end tell
end tell




--
Paul Berkowitz


> From: Larry McMunn <email@hidden>
> Date: Thu, 16 Dec 2004 11:16:52 -0500
> To: <email@hidden>
> Subject: Excel2004, System Events & NSReceiverEvaluationScriptError
>
> I'm moving a lot of scripts from Excel X to Excel 2004. I'm slowly getting
> comfortable with the changes, but there's a lot to relearn--especially without
> the ability to record to get a starting point. This makes debugging even more
> important. When I working on a script, I have problems checking it in
> debugging mode. I'm using Excel 2004 with the Service Pack applied and Script
> Debugger 3.0.8. A part of this particular project is making a PDF of a
> worksheet using the "Save As PDF" button in the "Print" window.
>
> The following script works exactly as expected when saved as an application
> and run with the source workbook open.
>
> When run from compiled mode, whether debugging is enabled or not, I get the
> following message --"System Events got an error:
> NSReceiverEvaluationScriptError: 4" upon clicking the "Save As PDF" button:
>
> -----------------------------------------------------
> tell application "Excel_2004"
>    activate
>    activate object worksheet "MyDesiredSheet"
>    tell worksheet "MyDesiredSheet"
>       set left header of page setup object to "xx"
>       set center header of page setup object to "Here's My PDF"
>       set right header of page setup object to "xx"
>    end tell
>    tell application "System Events"
>       tell process "Excel_2004"
>          keystroke "p" using command down
>          -- problem occurs at the next line
>          click button "Save As PDFŠ" of UI element 4 of window "Print"
>          keystroke "d" using command down
>          keystroke "My Desired Worksheet"
>          keystroke return
>       end tell
>    end tell
> end tell
> -----------------------------------------------------
>
> This happens as the script appears above and also if the 'tell application
> "System Events"' block is put outside the tell Excel block. This is just a
> small portion of the complete script. I would like to be able to run the
> script from Script Debugger as I work on it rather than closing and running as
> an application to test each change.
>
> Any help out there?
> --
>
> Sincerely,
>
> Larry McMunn
> President
>
> McMunn Associates, Inc.
> 900 Haddon Avenue, Suite 302
> Collingswood, NJ 08108
>
> (856) 858-3440
> ---------------------------------------------------------------
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Excel2004, System Events & NSReceiverEvaluationScriptError
      • From: Bill Cheeseman <email@hidden>
References: 
 >Excel2004, System Events & NSReceiverEvaluationScriptError (From: Larry McMunn <email@hidden>)

  • Prev by Date: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
  • Next by Date: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
  • Previous by thread: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
  • Next by thread: Re: Excel2004, System Events & NSReceiverEvaluationScriptError
  • Index(es):
    • Date
    • Thread