Strange Applescript Error : NEED HELP

I’ve writing AppleScripts at an internship for the last few months. I’m using a Leopard iMac with AppleScript version 2.0. The scripts I create need to be run on a lot of other systems. However I’ve been unable to run some of my scripts on one particular system (MacMini running Tiger and Applescript version 1.8.2). I upgraded the system to Leopard, but the problem still persists. The compiler’s unable to understand the most basic spreadsheet code. The scripts run just fine on my system which is why I’m posting. Bits of the code are as follows:

tell application “Microsoft Excel”

set CWB to choose file with prompt "Choose The Raw Data File" --- Choose File Box Opens
open CWB --- Workbook Opens
set namer to name of active workbook --- compiler shows value transferred to namer as 'missing value'
set name of active sheet to "Database" --- compiler shows value transferred to namer as 'missing value'

activate sheet "Database" of workbook namer --- This line obviously causes an error

end tell

This could just be a settings issue that I’m not aware of. However I’ve been searching for an explanation for this query for quite a while without any luck. I’m desperate as I need to get these scripts to run on the other systems ASAP. I’d be grateful if someone could point me in the right direction.

Hi,

this error is not strange, it’s logical :wink:

activate is a command of AppleScript’s dictionary to bring the targeted application to the front.
The dictionary of Microsoft Excel doesn’t know just an activate command, but activate object


.
activate object sheet "Database" of workbook namer
.

Thanks for the reply. But as I mentioned in my post, the script works just fine on my Leopard. What I’m basically confused about is the ‘missing values’ when i’m transferring the excel workbook’s name to a string. I’d be glad if you could help me out with that. Thanks.

Maybe it’s a timing problem,
the script tries to retrive the name of the sheet, before has opened completely.
Try this “controlled delay”


tell application "Microsoft Excel"
	set CWB to choose file with prompt "Choose The Raw Data File" --- Choose File Box Opens
	open CWB --- Workbook Opens
	repeat until exists workbook (name of (info for CWB))
		delay 0.5
	end repeat
	set namer to name of active workbook 
	set name of active sheet to "Database" 
	activate object sheet "Database" of workbook namer 
end tell

hey I tried adding the delay as specified by you. Didn’t work. The problem is that the repeat segment goes into an infinite loop as the exists workbook statement in the code evaluates to false everytime.

compiler statements are as follows:

info for alias “Macintosh HD:Users:joisekoh:Documents:AUS Scrap.xls”
{name:“AUS Scrap.xls”, creation date:date “Monday, December 4, 2006 11:34:39 AM”, modification date:date “Monday, December 4, 2006 11:34:39 AM”, size:5751, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:“xls”, displayed name:“AUS Scrap.xls”, default application:alias “Macintosh HD:Applications:Microsoft Office 2004:Microsoft Excel”, kind:“Microsoft Excel workbook”, file type:“TEXT”, file creator:“dosa”, type identifier:“com.microsoft.excel.xls”, locked:false,busy status:false, short version:“”, long version:“”}

excel workbook “AUS Scrap.xls”
false

info for alias…(this bit keeps repeating)

I still think it has something to do with applescript settings. Because if the code were faulty it wouldn’t work on any other system.

I am not sure whether Excel expects “.xls” here, so I would use:


exists workbook (short name of (info for CWB)) -- instead of: name

to see whether that gets rid of the extension,
or alternatively:


set (hasit,timeOutVal) to (false, 0)
repeat until hasit or timeOutVal > 1000
try
set tn to (name of (info for CWB))  
on error
set tn to "No value"
end try
if ".xls" is in tn's text from character -5 to -1 then
	set tn to tn's text from character 1 to -5
end if
set hasit to exists workbook tn
tell me to delay "0.3"
set timeOutVal to timeOutVal + 1
end repeat

I can’t test this on my machine as I have Leopard on it.

Hey…the short name technique doesn’t seem to be working. Neither is the .xls trick you suggested (second script). Like I said earlier, the script works just fine on my computer. So what I’m really looking for is a configuration/compatibility/settings based solution to this problem. I’m sorry but I really need to get these scripts working on THAT computer within the next week or so. Thanks a lot for your assistance anyway.