Here is another AppleScript version of a
prior vba script. This one creates a back of the current
workbook. It copies the last saved version of the current workbook to
a Backup
subdirectory below the directory in which that file was saved.
It adds a counter (ie, .001
) before the .xls(x)
extension.
Rather than merging cells to center headers, I prefer to have text centered
across selection
. This avoids problems with deleting and filling columns that
are cosed by merged cells. The following sets up a command to toggle centering
across columns.
Open up the AppleScript Editor, paste the following code and save it as
/Users/<your-username>/Documents/Microsoft User Data/Excel Script Menu
Items/AlignCentered\sca.scpt
. The \sca
in the filename creates a
keyboard shortcut control-shift-a
.
-- Align selected cells across selection
-- Copyright under GPL by Mark Grimes
-- Saving with '\sca' in the filename creates Shortcut: Crtl+Shift+a
tell application "Microsoft Excel"
--activate
tell range (get address selection) of active sheet
if (get count columns) > 1 or (get count rows) > 1 then
if (get horizontal alignment) is horizontal align center across selection then
set horizontal alignment to horizontal align general
else
set horizontal alignment to horizontal align center across selection
end if
else
if (get horizontal alignment) is horizontal align center then
set horizontal alignment to horizontal align general
else
set horizontal alignment to horizontal align center
end if
end if
end tell
end tell
I recently switched to a Mac and really miss my auto color cells VBA script for Excel. After quite a bit of digging (and trial-and-error) I managed to recreate the functionality using AppleScript. It is pretty slow, but it works!
Just like the VBA version, this automatically color codes cells to help
identify inputs, formulas, etc. For example, cells that contain only numbers
are colored blue, all formulas black, references to other workbooks are green
and cells that include the =OFFSET()
function (what I use for setting up
different scenarios) are rust.
Open up the AppleScript Editor, paste the following code and save it as
/Users/<your-username>/Documents/Microsoft User Data/Excel Script Menu
Items/AutoColorCells\scc.scpt
. The \scc
in the filename creates a
keyboard shortcut control-shift-c
.
We’ll after neglecting this blog for quite some time, I’m now back. I had to swap my laptop during the summer, and I decided to give one of the MacBook Pros a try. So I’ll be adding Perl on the Mac and the Mac in general to the topics covered here. My first dilemma with the new Mac was which perl to use.