Problem copying cells from Excel

Can anyone figure out why this doesn’t work? I marked the line where I’m getting the error…

-- App to speak sales figures on excel document with half second delay between figures
try
	tell application "Microsoft Excel"
		activate
		
		-- loop for mycolumnumns B thru J
		repeat with n from "1" to "9"
			
			if n = 1 then set mycolumn to "b"
			if n = 2 then set mycolumn to "c"
			if n = 3 then set mycolumn to "d"
			if n = 4 then set mycolumn to "e"
			if n = 5 then set mycolumn to "f"
			if n = 6 then set mycolumn to "g"
			if n = 7 then set mycolumn to "h"
			if n = 8 then set mycolumn to "i"
			if n = 9 then set mycolumn to "j"
			
			-- loop for rows 4 to 34
			repeat with myrow from 4 to 34
				
				set currentcell to mycolumn & myrow
				
-- **********Problem at line below**********
				copy range range of quoted form of (currentcell) of the active sheet
				
				set thisfigure to the clipboard
				
				say thisfigure
				delay 0.5
				
			end repeat
		end repeat
	end tell
on error
	activate application "Script Editor"
	beep
	display dialog "Damn thing doesn't work!" buttons {"OK"} default button 1
end try

This works for me:


try
	tell application "Microsoft Excel"
		activate
		
		-- loop for mycolumnumns B thru J
		repeat with n from "1" to "9"
			
			if n = 1 then set mycolumn to "b"
			if n = 2 then set mycolumn to "c"
			if n = 3 then set mycolumn to "d"
			if n = 4 then set mycolumn to "e"
			if n = 5 then set mycolumn to "f"
			if n = 6 then set mycolumn to "g"
			if n = 7 then set mycolumn to "h"
			if n = 8 then set mycolumn to "i"
			if n = 9 then set mycolumn to "j"
			
			-- loop for rows 4 to 34
			repeat with myrow from 4 to 34
				
				set currentcell to mycolumn & myrow
				set thisfigure to value of cell currentcell
				
				--removed copying value to clipboard. Do you still need it?
				
				say thisfigure
				delay 0.5
			end repeat
		end repeat
	end tell
on error
	beep
	display dialog "Oops!" buttons {"OK"} default button 1
end try

That worked perfectly! Thanks!

One other question, how could I have the script grab the contents of selected cells?

I tried the following, but they don’t seem to work

tell application "Microsoft Excel"
	activate
	set thisfigure to value of cell selection
	say item 1 of thisfigure
end tell

set thisfigure to selection			
say item 1 of thisfigure

Thanks again, that worked great.

One more question… can you get the position of the selected cell as well? Which column, which row?

Try something like this, Torajima:

tell application "Microsoft Excel" to {first column index, first row index} of selection

Or:

tell application "Microsoft Excel" to {first column index, first row index} of active cell

(Note that the results might differ between these methods, depending on the nature of the selection.)