Skip navigation

Monthly Archives: August 2008

So, I’m trying to figure out if an Excel Workbook is Read Only.

So I grab my Workbook from Application.Workbook and it has a property called ReadOnly.

I write a line of code like if (Application.Workbook.ReadOnly == false) { … }

Compiler error!  What?  Can’t convert type ‘bool’ to type ‘MsoTriState‘?  Of course I can’t.

Turns out ReadOnly (and most other properties that should be bools in the Workbook class) are not bool, but are instead an enum called MsoTriState.  Makes sense.  I figured this was probably a holdover from the days before .NET had invented nullable value types.

There’s only one catch.

MsoTriState – which from the tri in its name you might conclude has 3 states – actually has 5 states: msoCTrue, msoFalse, msoTriStateMixed, msoTriStateToggle, msoTrue.

Now because today isn’t the first time Evan has gotten burned, Evan decided rather than assume the obvious which would be to use the msoFalse and msoTrue enumeration values, Evan would consult the documentation first.

To my horror, I see this table:

Member name Description
msoCTrue Not supported.
msoFalse False.
msoTriStateMixed Not supported.
msoTriStateToggle Not supported.
msoTrue True.

So let me get this straight.  The ReadOnly property is not a 2 state true/false bool, it’s a 3 state MsoTriState enum, except the TriState is actually has five states, but only 2 of those states are supported.