Hi jason
I grabbed the script from osx hints.
It's wrong because it works only if the selection is in table 1 of sheet 1.
The reason is that the filter:
table whose selection range is not missing value
is verified by every table.
_When nothing is selected the 'value' of selection range is not missing value._
Try to run this script with a range selected in table 2 of sheet 2 in a doc containing 3 sheets.
In the log report you will see that for tables where nothing is selected the result is not missing value but nothing at all.
tell application "Numbers"
tell document 1
-- DETERMINE THE CURRENT SHEET
set {currentsheetindex, currenttableindex} to {0, 0}
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with j from 1 to x
try
log "j = " & j
set theRange to (selection range of table j) as text
log theRange
on error errMsg number errNum
log errMsg
set {currentsheetindex, currenttableindex} to {i, j}
exit repeat
end try
end repeat --table
end if
end tell
if currentsheetindex > 0 then exit repeat
end repeat -- sheet
if the currentsheetindex is 0 then error "No sheet has a selected table."
log {currentsheetindex, currenttableindex}
-- GET THE VALUES OF THE SELECTED CELLS
tell sheet currentsheetindex to tell table currenttableindex
set the range_values to the value of cells of the selection range
end tell -- table of sheet
end tell -- document 1
end tell -- application
Yvan KOENIG (from FRANCE dimanche 25 janvier 2009 17:30:50)