How to declare a worksheet to a variable and activate that worksheet using C# in invoke code

Hi,

I want to assign a worksheet to a variable and activate that worksheet whenever i wanted. Could someone please help? Below error for your reference

Main.xaml: No compiled code to run
error CS1061: ‘Microsoft.Office.Interop.Excel.Workbook’ does not contain a definition for ‘worksheets’ and no extension method ‘worksheets’ accepting a first argument of type ‘Microsoft.Office.Interop.Excel.Workbook’ could be found (are you missing a using directive or an assembly reference?) At line 14

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"YOUR_EXCEL_FILE_PATH");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
xlWorksheet.Activate();

Regards,
Karthik Byggari

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.