more of an aspiration than a claim

Hidden Excel Sheets After Writing to the Excel Workbook

Are your Excel sheets missing after programmatically writing to your workbook?

I came across this when trying to write into an Excel spreadsheet from a C# application (should still be application to VB or other languages). This is particulary confusing when you have never written any Excel interacting code before and do not know about hidden sheets.

After writing to the Excel workbook, I found that all sheets had disappeared, although the file size had increased and I could see signs of my newly added values in the binary Excel file.

One of my colleagues pointed out that he could see them whilst using IE, but they disappeared once he saved it to disk and opened the Excel file with Office. He then twigged what was going on and managed to unhide them, see the Windows/Unhide menu option in Excel.

To fix this issue, you need to make sure the Excel Window in your Excel Workbook is active. The trick is to have code similar to the following:

ExcelConnection.Workbook.Windows[1].Activate();

Even if the Excel sheet was previously visible before you opened the Excel file, it seems to get reset.