tags:

views:

319

answers:

1

I'm trying to use the SpecialCells method in a VSTO project using c# against the 3.5 framework and Excel2007.

Here's my code:

Excel.Worksheet myWs = (Excel.Worksheet)ModelWb.Worksheets[1];

Range myRange = myWs.get_Range("A7", "A800");

//Range rAccounts = myRange.SpecialCells(XlCellType.xlCellTypeConstants, XlSpecialCellsValue.xlTextValues);

Range rAccounts = myWs.Cells.SpecialCells(XlCellType.xlCellTypeConstants, XlSpecialCellsValue.xlTextValues);

When I run this, it throws an exception... System.Exception._COMPlusExceptionCode with a value of -532459699

Note that I get the same exception if I switch(uncomment one and comment the other) the above Range rAccounts line.

A: 

I figured it out... the worksheet was protected!

myWs.Unprotect(Properties.Settings.Default.PasswordSheet);

fixes it...for those playing along at home...don't forget to protect the sheet when you're done.

myWs.Protect(Properties.Settings.Default.PasswordSheet, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
w4ik