Excel 2004

i’m trying to update old excel scripts to work with excel 2004. admittedly i’m not the best scripter in the world, but this is becoming a huge pain. at the least, i was wondering if anyone knew if there was a way to refer to cells using the old R1C1-notation. basically, i have the row number and the column number but can’t figure out a way to select the cell. it appears Excel only recognizes the A1-notaion where i would need to figure out the column letter from the column number. can anyone help me out with this?

You can use “cell x of column y” or “cell y of column x”. You can address cells directly like that, or get a reference with something like:

	set theCell to item 1 of (get areas of cell x of row y)

It’s all a bit harder than it needs to be, it seems to me.


Shane Stanley

You could also try the following.

Enjoy.


(* 
  ---------------------------------------------------
	use some globals and give them some 
	initial values
   --------------------------------------------------- 
*)

global myLookTable
global LookupTableInitialized

set myLookTable to {}
set LookupTableInitialized to false

(* 
  ---------------------------------------------------
	This function sets up a table
	that will be used to get the
	correct column name for Excel
   --------------------------------------------------- 
*)
on InitializExcelColumnLookupTable()
	
	-- If the table has already been
	-- set up then just return
	if LookupTableInitialized then return
	
	set AlphaList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
	set outerLetter to ""
	set innerletter to ""
	set indexString to ""
	set numListItems to 0
	set MaxExcelColumns to 256
	
	repeat with i from 0 to 26
		if i is greater than 0 then
			set outerLetter to item i of AlphaList
		end if
		
		repeat with j from 1 to 26
			set innerletter to item j of AlphaList
			if outerLetter is not equal to "" then
				set indexString to outerLetter & innerletter
			else
				set indexString to innerletter
			end if
			
			set the end of myLookTable to indexString
			set numListItems to numListItems + 1
			
			if numListItems is equal to MaxExcelColumns then
				exit repeat
			end if
			
		end repeat
		
		if numListItems is equal to MaxExcelColumns then
			exit repeat
		end if
		
	end repeat
	
	-- Mark the table as being set up
	set LookupTableInitialized to true
	
end InitializExcelColumnLookupTable

(* 
  ---------------------------------------------------
	This function is the one that should be
	called to get the correct Excel column
	name
   --------------------------------------------------- 
*)
on GetExcelColumnLetter(idx)
	
	if not LookupTableInitialized then
		InitializExcelColumnLookupTable()
	end if
	
	return item idx of myLookTable
	
end GetExcelColumnLetter

(* 
  ---------------------------------------------------
	This following code is only here
	to show how to use the code above
   --------------------------------------------------- 
*)
set foo to GetExcelColumnLetter(42)
set bar to GetExcelColumnLetter(25)
set result to {foo, bar}

return result

thanks a ton guys, this was really driving me crazy. as much as i like the fact microsoft is updating applescript capability for 2004, it’s giving me a ton more work. thanks again.