A very reasonable question, as you say a non-active sheet's previous
RangeSelection must be stored somewhere (or default A1). However it is not
exposed, neither as an object nor as an address..
The RangeSelection and activecell are properties not directly of the sheet
but of a Window. A workbook always has at least one window, so FWIW you can
get the range selection of a non active wb. For the moment I'll ignore here
what occurs with if user opens multiple windows.
In passing, it's worth noting that if an embedded worksheet chart is
selected, unqualified ActiveCell will fail, would need to do
Windows(2).ActiveCell.
Somewhere hidden (invisible name-space maybe) the sheet stores certain
properties to be applied to window properties when the sheet becomes active.
When deactivated, the properties of the newly activated sheet are applied to
the Window object, RangeSelection & ActiveCell of the deactivated sheet are
no longer accessible.
Easy workaround is temporarily reactivate the sheet and get the selection.
Set newSh = Activesheet
Set ws = Workbooks("abc"),Worksheets("Sheet1")
maybe disable screen updating here
ws.parent.activate
ws.activate
set rng = Selection ' verify selection is a range
'or set rng = Windows(1).RangeSelection
' bit more here, not yet 100% sure to return a range
newSh.parent.activate
newSh.Activate
Briefly here's an outline of another workaround
- in ThisWorkbook SheetDeactivate
- verify the deactivated sheet is a worksheet, If Sh.Type = xlWorksheet then
- disable events
- trap the new activesheet, Set newSh = ActiveSheet
- reactivate the deactivated sheet, Sh.Activate
- Sh.Names.Add "LastSelection", Windows(1).RangeSelection (assumes chart not
selected)
- reactivate, newSh.Activate
- re-enable events
You can then reference the "lastSelection" from
"'sheet-Name'!LastSelection", if the name doesn't exist use default A1
Regards,
Peter T