SpecialCells at VSTO

I am trying to use the SpecialCells method in a VSTO project using C # for 3.5 framework and Excel2007.

Here is 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 line of the rAccounts range.

+3
source share
1 answer

I realized this ... the worksheet was protected!

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

corrects it ... for those who play at home ... do not forget to protect the sheet when 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);
0
source

Source: https://habr.com/ru/post/1696752/


All Articles