I know this topic has been addressed a few times in the past, but I can't find anything along these exact lines.
I'm using code to write a value to Excel - the workbook opens and the input is consistently written into the correct cell reference, the workbook is saved and closed all fine. However, the the worksheet last open/saved is the one that is written to, rather than the one I need/specify.
I'm using Excel 2010 and an xlsb file.
My code, adapted from an example on a blog post from a few years ago, looks like:
Excel.Application ExcelDataconnectorSourceFile = new Excel.ApplicationClass(); ExcelDataconnectorSourceFile.Visible = true; Excel.Workbook ExcelWorkbook = ExcelDataconnectorSourceFile.Workbooks.Open("<path to sheet>"); Excel.Sheets ExcelSheets = ExcelWorkbook.Worksheets; Excel.Worksheet LoggingSheet = (Excel.Worksheet)ExcelSheets.get_Item("Logging"); ExcelDataconnectorSourceFile.Cells[2,8] = _CurrentCount + 1; ExcelWorkbook.Save(); ExcelWorkbook.Close(); ExcelDataconnectorSourceFile.Application.Quit();I've tried replacing the string parameter in get_Item with the number of the sheet, but it didn't help.