Pergunta
Estou tentando usar o método SpecialCells em um projeto VSTO usando c# na estrutura 3.5 e Excel2007.
Aqui está meu código:
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);
Quando executo isso, ele lança uma exceção ...
System.Exception._COMPlusExceptionCode with a value of -532459699
Observe que recebo a mesma exceção se eu alternar (descomentar um e comentar o outro) a linha Range rAccounts acima.
Solução
eu descobri...a planilha estava protegida!
myWs.Unprotect(Properties.Settings.Default.PasswordSheet);
resolve...para quem está brincando em casa...não esqueça de proteger o lençol quando terminar.
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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow