Ich möchte meine Auswahl mit AppleScript umkehren. Dies ist analog zur Funktionalität von Adobe Photoshop (und anderen Adobe-Produkten) „Auswahl umkehren (Strg/Cmd + I, um die zuvor ausgewählte Auswahl aufzuheben und auszuwählen, was nicht ausgewählt war)“
tell application "Microsoft Excel"
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
(Alle Zellen im Blatt werden ausgewählt, die ursprünglich nicht ausgewählt waren)
Endlich habe ich eine Lösung. Vielen Dank an Monomeeth für die VBA-Version, die mich auf den richtigen Weg gebracht hat. (Und dies auch unter Windows möglich machen)
Funktioniert ähnlich wie die Version von Monomeeth. Es hat einen Bereich, der aus Leistungsgründen berücksichtigt wird. Stellen Sie es ein, indem Sie diese Zeile entsprechend ändern:
set range_considered to range "A1:Z100" of active sheet
Hier ist es:
-- use "intersect" to test whether the considered area overlaps with the selected area
-- use union to append non-selected cells to a new range
tell application "Microsoft Excel"
set screen updating to false -- optimize performance
--tell active sheet of active workbook
set range_considered to range "A1:Z100" of active sheet
set range_selected to selection
set range_new_selection to "Nothing"
-- setup ref vars for selection
tell selection to set {range_selected_row_index, range_selected_column_index, range_selected_row_count, range_selected_column_count} to {get first row index of selection, get first column index of selection, get count rows of selection, get count columns of selection}
-- setup ref vars for considered
tell selection to set {range_considered_row_index, range_considered_column_index, range_considered_row_count, range_considered_column_count} to {get first row index of range_considered, get first column index of range_considered, get count rows of range_considered, get count columns of range_considered}
-- go column by column and iterate each row in each column
repeat with considered_col_step from range_considered_column_index to range_considered_column_count
repeat with considered_row_step from range_considered_row_index to range_considered_row_count
set range_this_cell to range (get address row considered_row_step of column considered_col_step of active sheet) of active sheet
log range_selected
try
set range_test to intersect range1 range_this_cell range2 range_selected -- test for intersection with selected
(*use try to detect error. Will fail if cell is within selection*)
log "TRUE Intersected"
on error
(*Create or append to range_new_selection*)
log "FALSE intersected"
if range_new_selection is "Nothing" then
set range_new_selection to range_this_cell
else
set range_new_selection to union range1 range_new_selection range2 range_this_cell
end if
end try
end repeat
end repeat
try
select range_new_selection
on error
log "Could not select new range."
end try
set screen updating to true -- optimize performance
end tell
Ich habe eine Weile an dieser Frage gearbeitet und, als ich auf eine Mauer stieß, beschlossen, es stattdessen mit Visual Basic zum Laufen zu bringen. Ich hoffe, dass es dadurch einfacher wird, den Code in AppleScript richtig hinzubekommen, also teile ich den Visual Basic-Code, falls er jemand anderem hilft, eine AppleScript-Version zum Laufen zu bringen - nicht, dass ich das selbst aufgegeben hätte noch! :)
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
ANMERKUNGEN:
Set s2 = Range("A1:Z100")
den Bereich des Blattes, auf den sich der Code bezieht, auf den Bereich von A1:Z100 begrenzt. Dies kann jedoch bei Bedarf an eine größere Fläche angepasst werden.
Synoli
H18
, oder über ? hinausgehtH20
? Wie wäre es mitA200
?ZZ999
?XFD1048576
?)Jonathan Komar
Synoli
Jonathan Komar
Monomet
Monomet
Monomet
Monomet
Jonathan Komar