nic_m
July 28, 2009, 8:49am
#1
Hi Folks,
I need to clear the format of all cells in a given worksheet as part of an applescript.
This step is needed so that when I copy a range from one sheet and concatenate it with other data the format all play nicely together
If i were to do this manually I would select all in the active sheet and the go to format cells and choose the number format general.
does any one know how to do this using applescript?
thanks in advance
nic
nic_m
July 29, 2009, 7:01am
#3
Hi Mike
thanks for your response - but it’s not working. I keep getting an error message that the object I am trying to access doesn’t exist.
I modified it a little to read:
tell application "Microsoft Excel"
set activesheet to worksheet "All"
set number format of (cells of activesheet) to "General"
end tell
any suggestions? (greatly appreciated)
i figured out another way of doing this that works, but it is fairly rudimentary (and chunky)
set downarrow to ASCII character 31 -- Down arrow
tell application "Microsoft Excel"
activate
activate object sheet "All"
tell application "System Events"
keystroke "a" using {command down}
keystroke "1" using {command down}
keystroke tab
keystroke tab
keystroke downarrow
keystroke "g"
keystroke return
end tell
end tell
I have had a look at the MS-Excel manual. Sometimes it has been helpful, in this case, not so.
A more generalized syntax would be
tell application "Microsoft Excel"
set number format of (cells of (sheet "Sheet1" of workbook "Workbook1.xls")) to "general"
end tell
or
tell application "Microsoft Excel"
set number format of (cells of (sheet "Sheet1" of active workbook)) to "general"
end tell
nic_m
July 31, 2009, 3:23am
#5
thanks Mike,
this works
I also had something else recommended to me which (seems to) work nicely
tell active sheet
clear range formats used range
end tell -- clears formatting of active sheet. reduces formatting issues when concatenating further in the script.