How to skip ''Applications are located lazily'' or it's an Excel bug?

Found one small problem using AppleScript/Excel. I’m wondering if somebody can tell what’s wrong? Thanks in advance!

When a script (AppleScript) contains ‘tell’ block like this


     tell application "Microsoft Excel"

     end tell

the Xcode (like ScriptEditor) always saves path/reference to Excel within compiled script
at the origin Mac (where the program is compiled) (i.e. feature of AppleScript named
‘Applications are located lazily’ from
http://developer.apple.com/documentation/applescript/Conceptual/ApplescriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW2).

But when the customer has Excel installed to different location (like to the
‘Office 2008’ folder instead of default ‘Microsoft Office 2008’) any script-program with
block like above shows error message:

I’ve found an obvious solution - make property/variable := “Microsoft Excel” and work with
Excel from such block:

property MSXL : "Microsoft Excel"
tell application MSXL
	launch
...

end tell

It works well while we are not accessing active sheet/book.
For example line with “active workbook” generates error at compile time. This script
doesn’t compile and generates an error “Expected end of line, etc. but found identifier.”
at the last (before end tell) line.

property MSXL : "Microsoft Excel"
tell application MSXL
	launch
	make new document
	activate
	set n to name of active workbook
end tell

while this scripts compiles perfectly:


--property MSXL : "Microsoft Excel"
tell application "Microsoft Excel"
	launch
	make new document
	activate
	set n to name of active workbook
end tell

Any ideas what I’m doing wrong?

I’m not familiar with your error. It sounds strange that if excel isn’t in the same location as the one on the computer where the code was compiled that you’d have this problem.

A solution to the error could be to reference the application by application id instead of application name. An example of this is seen just above the “Special Considerations” section in the link you posted. Here’s how you can get the id of an application:

set theApp to "Microsoft Excel"
tell application theApp to launch
tell application "System Events"
	tell process theApp
		set bundleIdentifier to bundle identifier
	end tell
end tell
return bundleIdentifier --> "com.microsoft.Excel"

Then you can use that in your code. Note: this is a 10.5 solution only.

tell application id "com.microsoft.Excel"
	launch
end tell

regulus6633
Thank you very much! It worked perfectly!
Unfortunately it seems it requires to have alternate version for 10.4 users. :mad: