Workbook.ChangeFileAccess fails violently

Magne 166 Reputation points
2021-10-21T17:46:48.21+00:00

I start an Excel process from C#
If I open an existing workbook in ReadOnly mode and don't do any changes and no saving, it is possible to toggle mode by Workbook.ChangeFileAccess(XlFileAccess.xlReadWrite) or Workbook.ChangeFileAccess(XlFileAccess.xlReadOnly)

However, if I open the workbook without ReadOnly then I may change file access to ReadOnly, but not back again to ReadWrite
Exception: System.Runtime.InteropServices.COMException: 'The object invoked has disconnected from its clients. (0x80010108 (RPC_E_DISCONNECTED))'

Similarly it fails if open ReadOnly, change file access to ReadWrite, make a change, save it and then try to change access to ReadOnly followed by change to ReadWrite.

Is this a bug or by design, if latter please explain rationale

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.