anakic
anakic

Reputation: 2978

Disable editing a workbook while processing (VSTO)

I have a VSTO addin that performs some processing on the active Excel workbook. Processing can take from a few seconds to a couple of minutes, during which time I'd like to keep Excel responsive to the user but I want to prevent the user from modifying the workbook. Once processing is done, the workbook should go back to being editable.

I could set application.Interactive to false but that would disable any interaction with Excel which I don't want to do. I want to let the user interact with current workbook, the ribbon and other workbooks, as long as the interactions do not have any impact on the workbook that's being processed.

Is there a way to do this? Basically, if there was a settable IsReadonly property on the workbook object, that would be ideal.

Upvotes: 0

Views: 131

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

The best solution is to display a dialog window which doesn't let users switch to the Excel workbook until your calculations/operations are done. Note, using the Excel object model from secondary threads is not safe because Office applications use the single-threaded apartment model. So, it make sense to extract the data, do the required modifications and then set the data back on the main thread. Otherwise, you need to display a modal progress window to a user and do the requirements modifications on the main thread.

Upvotes: 1

Related Questions