first tried posting on the Numbers list but to my idea this is more an AppleScript mistake I'm making.
I have a Numbers document with some sheets and tables. I'm trying to have all x amount of tables from the various sheets written to x amount of PDF documents. With the code below I'm successful in getting PDF documents of the first sheet. Looping through the second sheet fails. Can anybody explain me what I'm doing wrong?
tell application "Numbers"
activate
tell document 1
activate
repeat with i from 1 to count of sheets
tell sheet i
activate
end tell
set nameSheet to name of sheet i
tell sheet i
repeat with j from 1 to count of tables
tell table j
activate
end tell
set nameTable to name of table j
tell table j
set lastCell to name of last cell
set selection range to range ("A1 : " & lastCell)
try
tell application "System Events" to keystroke "a" using {command down}
tell application "System Events" to keystroke "c" using {command down}
set myPath to (path to desktop folder as text) & nameTable & ".pdf"
set myFile to (open for access myPath with write permission)
set eof myFile to 0
write (the clipboard as («class PDF »)) to myFile
close access myFile
end try
end tell -- table j
end repeat --j is count of tables
end tell --tell sheet i
end repeat --i is count of sheets
end tell --doc 1
end tell --app Numbers