问题
ExcelApplication.Workbooks.Count
is showing count = 0 even when I have a document open.
ExcelApplication.Workbooks.Count
shows count = 1 when the document opened is not in protected view. But when the opened document is PROTECTED VIEW the ExcelApplication.Workbooks.Count
shows 0.
Why the workbook count is 0 in case of protected view excel?
回答1:
Because:
A workbook displayed in a Protected View window is not a member of the Workbooks collection.
If you need to get a handle on a protected workbook:
using (var protectedWorkbook = ExcelApplication.ProtectedViewWindows(1).Workbook)
{
// do stuff
}
A robust solution would account for the possible fault condition of multiple ProtectedViewWindows
. The above code assumes there is one and only one.
来源:https://stackoverflow.com/questions/58458188/why-excelapplication-workbooks-count-is-showing-zero-even-when-i-have-an-excel-w