0

I am writing a Add-In for excel where i have to store workbookspecific settings in the excel file. I tryed to create a new worksheet, and hide it.

settingsSheet.Visible = XlSheetVisibility.xlSheetHidden;

Now my application was always writing to my open worksheet, not the hidden settingsworksheet. If i remove the part which hides the worksheet, it works fine.

Is there a way to write to hidden excel worksheets? Or is there a better way to store settings?

edit: aditional code

Worksheet newWorksheet;
string newWorksheetname = "SettingsSheet";
foreach (Worksheet sheet in ActiveWorkbook.Sheets)
        {
            if (sheet.Name == newWorksheetname)
            {
                newWorksheet = sheet;                   
            }
        }
if (newWorksheet == null)
 {
  newWorksheet = (Worksheet)Globals.ThisAddIn.Application.Worksheets.Add();
            newWorksheet.Name = newWorksheetname;
  }
newWorksheet.Visible = XlSheetVisibility.xlSheetHidden;
newWorksheet.Cells[1,1].Value="settingsValue";
Jonas Wyss
  • 152
  • 1
  • 11

2 Answers2

0

are you properly referencing the worksheet? I think you are referencing the ActiveSheet instead.

winghei
  • 632
  • 4
  • 9
  • Yes, I'm pretty sure that I'm referencing the right worksheet. Because when im testing the same code without hiding the settingsworksheet everything work properly. And the settings worksheet was never my ActiveWorksheet when i run the code. – Jonas Wyss Aug 10 '16 at 12:24
  • It would be nice if you could add some more details on your post. e.g. line where settingsSheet was defined and when you try to populate the worksheet – winghei Aug 10 '16 at 12:42
0

I didn't found any solution to my problem so I found a method of storing xml in a excel file but not in a hidden sheet. What is the best way to store XML data in an Excel file

Community
  • 1
  • 1
Jonas Wyss
  • 152
  • 1
  • 11