I am trying to convert the following four VBA Macros to AppleScript for MS Excel. All I need to do is retain the selection size and move everything around by one.
[format]Sub MoveSelectionUp()
Selection.Offset(-1, 0).Select
End Sub
Sub MoveSelectionDown()
Selection.Offset(1, 0).Select
End Sub
Sub MoveSelectionLeft()
Selection.Offset(0, -1).Select
End Sub
Sub MoveSelectionRight()
Selection.Offset(0, 1).Select
End Sub
[/format]
Here are the four sub routines you requested in Applescript. The first tell block shows how to call the routine. This is brute force. There is no error checking: a range must be selected and it must have room to move in whatever direction is selected. Hope they help.
tell application "Microsoft Excel"
set myRange to selection
my moveSelectionUp(myRange)
--my moveSelectionDown(myRange)
--my moveSelectionLeft(myRange)
--my moveSelectionRight(myRange)
activate
end tell
on moveSelectionUp(theRange)
tell application "Microsoft Excel" to select (get offset of theRange row offset -1)
end moveSelectionUp
on moveSelectionDown(theRange)
tell application "Microsoft Excel" to select (get offset of theRange row offset 1)
end moveSelectionDown
on moveSelectionLeft(theRange)
tell application "Microsoft Excel" to select (get offset of theRange column offset -1)
end moveSelectionLeft
on moveSelectionRight(theRange)
tell application "Microsoft Excel" to select (get offset of theRange column offset 1)
end moveSelectionRight
This is great, thank you! I have replaced all the VBA with AppleScript so I don’t have to have macro-enabled spreadsheets, so very nice to have this be able to work in any worksheet.
My apologies for the late reply, I hadn’t been on in a while and thought I received emails when a reply was posted but I have updated that setting.