Home » excel » c# – What object type are multiple selected sheets in Excel?

c# – What object type are multiple selected sheets in Excel?

Posted by: admin May 14, 2020 Leave a comment

Questions:

Contrary to what I would think, multiple selected sheets are not a Worksheets object type.

After multi-selecting 2 or more sheets. The way I get the selection is as so:

var selection = ExcelApp.Selection; //Returns object type

I’ve tried getting the “Name” property to try and give me a hint by using late binding with:

string name = selection.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, selection, null).ToString();

But this throws errors for the given selection type.

Any ideas?

How to&Answers:

In VBA, ActiveWindow.SelectedSheets returns a Sheets collection, so I imagine it will be similar in C#

Yep:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.window.selectedsheets(v=office.11).aspx