Return sheet properties based on sheets name in Excel

-1

I'm trying to return worksheet properties based on a sheet name. If the name exists in the workbook then it returns all the properties a worksheet contains and if it can't find the sheet it will just return null.

I've tried to do this 2 separate ways.

1.

Excel.Worksheet sheet = (Excel.Worksheet)this.Sheets["Sheet2"];

Which gives me this error

'Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))'
 var test = from s in Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets
               where s.Name.Equals("Sheet2")
               select s;

Which returns nothing.

c#
excel-interop
asked on Stack Overflow Jan 15, 2021 by Craig Gallagher

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0