3

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.

e-sushi
  • 13,786
  • 10
  • 38
  • 57
w4ik
  • 1,276
  • 2
  • 19
  • 33
  • If you see a COMPlus class of exception it is an HResult error bubbling up from the interop layer (i.e. in this case from the automation interface - Excel.12 API). i.e. unlikely to be directly the result of a syntax error or a logic error. as in this case the dev was using the code to perform an unsupported operation on the Excel process. Running the same code in VBA would have quickly unveiled the problem (as a troubleshooting step). – Anonymous Type Jan 08 '13 at 02:57

1 Answers1

0

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
  • 1,276
  • 2
  • 19
  • 33