How can I invert my selection in Microsoft Excel using AppleScript? (selection itself, not properties of selection) I'd like to invert my selection with AppleScript. This is analogous to Adobe Photoshop's (and other Adobe products) functionality &quot;Invert selection (Ctrl/Cmd + I to deselect what was previously selected and select what was not selected)&quot;

I can select a group of cells with AppleScript.
I can get selected range with AppleScript
I can loop selected cells
I'd like to select all cells that are not currently selected

Code
tell application &quot;Microsoft Excel&quot;
    repeat with item_cell from 1 to count large of selection -- all cells in selection
        --do stuff with selected cells
    end repeat
    
    -- index of selected cells technique, not sure whether helpful
    set sel_range to selection
    tell selection to set {rowIndex, columnIndex, rowCount, columnCount} to {get first row index of sel_range, get first column index of sel_range, get count rows of sel_range, get count columns of sel_range}
end tell

Originally Selected Cells

Desired Selection
(All cells in the sheet are selected that were not originally selected)
I've been working on this question for a while and, hitting a brick wall, decided to try and get it to work using Visual Basic instead. My hope is that doing this will make it easier to get the code right within AppleScript, so I'm sharing the Visual Basic code in case it helps someone else to get an AppleScript version working - not that I've given up on this myself yet! :)

Sub InvertSheet()

Set s1 = Selection
Set s2 = Range("A1:Z100")
Set sinv = Nothing

For Each s In s2
If Intersect(s, s1) Is Nothing Then
If sinv Is Nothing Then
Set sinv = s
Else
Set sinv = Union(sinv, s)
End If
End If
Next

If sinv Is Nothing Then
Else
sinv.Select
End If
End Sub


NOTES: 


I did come across a problem - namely that I couldn't find a way to get this to apply to the entire sheet without it causing Excel to hang for extremely long periods of time (probably because it has to check 1,048,576 rows and 16,384 columns) to do so.
To get around this problem I used Set s2 = Range("A1:Z100") to limit the area of the sheet that the code applies to to the range of A1:Z100. However, this can be changed to suit a larger area if needed.
I imagine trying to cover the whole sheet will be a problem within AppleSCript as well.