Excel get the current multiple selection

Add-in Express™ Support Service
That's what is more important than anything else

Excel get the current multiple selection
 
andrew.cutforth




Posts: 6
Joined: 2014-06-05
Currently in my .Net plugin for Excel I can use the following code to get the current user selected range:
Excel.Range Sel = (Excel.Range)ExcelApp.Selection;

But what if the user has CRTL-clicked on multiple individual cells. How do I get the selection then?

Is that multiple ranges?

Thanks
Posted 17 Nov, 2020 08:09:57 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Andrew,

That will be an Excel.Range having multiple items (each of them is of the Excel.Range type) in the Range.Areas property. See https://docs.microsoft.com/en-us/office/vba/api/excel.range.areas.

If many cells are selected, only one cell will be active: see https://docs.microsoft.com/en-us/office/vba/api/excel.window.activecell.

Also, ExcelApp.Selection may return things other than Range. In the project described at https://www.add-in-express.com/creating-addins-blog/2012/02/21/excel-shapes-events/, I use this fact to find out how the user selects, groups, ungroups, unselects, moves, resizes and renames shapes.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Nov, 2020 10:09:02 Top