I just tried using Office Interop
Excel = Microsoft.Office.Interop.Excel;
I'm looking out for a way with which I can make a particular worksheet (as Active worksheet) in the Excel workbook.
Something like this:
if (checkBox1.checked)
// Excel.worksheet.active = "Sheet 1";
else
// Excel.worksheet.active = "Sheet 2";
The code
Excel.Application xlApp;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
Excel.Range chartRange;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Name.Equals("Mark Sheet");

2 answers
This line:
xlWorkSheet.Name.Equals("Mark Sheet");should be:
The Equals method is only used for comparisons.
To make, say, the second worksheet active:
answered one year ago by:
17279
Error
Ambiguity between method 'Microsoft.Office.Interop.Excel._Worksheet.Activate()' and non-method ''Microsoft.Office.Interop.Excel.DocEvents_Events.Avctivate' Using method group
I'm just trying to open an existing file and save file with the required sheet as an active sheet. I did something like this:
But the file is not overwritten,
An empty file 'Book2.xls' is getting saved in 'My Documents' folder.
answered one year ago by:
412
17279
It's a compiler warning rather than an error - if you ignore it, it should work fine (it did when I tried it just now). If you want to get rid of the warning then change xlWorkSheet2.Activate(); to: ((Excel._Worksheet)xlWorkSheet2).Activate();