• 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: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)


  • Subject: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • From: Ted Wrigley <email@hidden>
  • Date: Fri, 21 Mar 2014 08:00:41 -0700

Still a scope issue, because you went a little overboard.  :-)  note the following:
  • worksheets are objects normally contained by workbooks, so you don’t need to use a handler to invoke them from within excel
  • be careful with reverse scoping: activate is a applescript command that the application Excel will recognize, but Excel’s objects may not recognize it which might throw an error and might not do what you expect. to activate a particular sheet or workbook, use Excel’s activate object command.
  • display dialog is an exception to the rule: you often want to call it from within an application tell block, so that the alert shows up in that application rather than in the applescript editor.
I would rewrite the main block like so:

tell application "Microsoft Excel"
activate
set WB to workbook "TestBook"
tell WB
set WS1 to sheet "one"
set WS2 to sheet "two"
set WS3 to sheet "three"


get address of active cell


-- a handler call is not needed here, since sheets are objects contained by workbooks
--my test_scope(WS1)
tell WS1 -- WS! is already a 'sheet' object, so no need to specify it with the 'sheet' keyword
activate
get address of active cell
end tell
end tell
end tell

On Mar 21, 2014, at 12:04 AM, email@hidden wrote:

From: Alastair Leith <email@hidden>
Subject: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
Date: March 21, 2014 at 12:04:46 AM PDT
To: asu <email@hidden>


global WB, WS1

to test_scope(sheetReference)
tell application "Microsoft Excel"
activate
tell sheet sheetReference
activate
get address of active cell
end tell
end tell
end test_scope

on DD(msg)
display dialog msg buttons {"OK"} default button 1
end DD

tell application "Microsoft Excel"
set WB to workbook "TestBook"
set WS1 to sheet "one"
set WS2 to sheet "two"
set WS3 to sheet "three"
get address of active cell
end tell


my test_scope(WS1)
tell WB
activate WS1
end tell



This script is generating an error on the highlighted line (in red):
Microsoft Excel got an error: The object you are trying to access does not exist
This is the offending object:
active cell of sheet («class asDB» id (application "Microsoft Excel") of worksheet 1) of application "Microsoft Excel"

I notice there a two references to Microsoft Excel in the object evaluation, is this a syntactical issue that I can clean up because I'm referencing to Excel in the tell statement and in the variable?

Or is it still a scope issue?

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
      • From: Christopher Stone <email@hidden>
  • Prev by Date: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Next by Date: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Previous by thread: Printing Problems with QXP10
  • Next by thread: Re: Scope riddle I can't seem to solve. (Probably very easy to solve for an experienced coder)
  • Index(es):
    • Date
    • Thread