Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Excel is in dirty state

Tags:

c#

excel

Is there any way I can know if Excel is in dirty state or not.

By dirty state I mean:- When you do anything on Excel and close save button - Excel asks you to save the file. So there must be some flag which is set when the file is edited.

Can I know the status of an Excel file through C# code?

Searched a lot, but not much help is available. One option is there which allows you to know if Excel is in edit state or not by looking at GetRibbonControlEnabled("FileNewDefault")

In this case you can see if Excel is in edit state only at the time when you execute this method.

What if I want to know if Excel was edited/made dirty since the time it was open.

Please don't advice to start to background thread which keeps looking if Excel was in edit mode by using the above function.

An help will be extremely appreciated.

like image 588
Gurinder Raj Avatar asked Mar 12 '13 15:03

Gurinder Raj


People also ask

How do I know if my Excel file is corrupted?

The following are common signs that your Excel file is corrupt. When you try to open your file and it fails to respond, there is a chance it is corrupt. Sometimes you may get the error message 'Unable to read file'. Another error you are likely to come across is 'Excel Cannot Open the File '(Filename)'.

What is a dirty cell in Excel?

If the application is in manual calculation mode, using the Dirty method instructs Excel to identify the specified cell to be recalculated. If the application is in automatic calculation mode, using the Dirty method instructs Excel to perform a recalculation.

How do you tell if an Excel file has been modified?

In the Review tab, select Show Changes. Changes are shown in the pane with the most recent changes on top, in the order the changes were made. You can see who made edits, exactly where in the workbook, when, and what they changed.

Do you want us to recover as much as we can Excel?

Do you want us to try recovering the file as much as we can? If you trust the source of this workbook, then click Yes” error. In this case, you can open the file in read-only mode and move its contents in a separate spreadsheet.


1 Answers

Take a look at the Workbook.Saved property. It will tell you if the user has modified the document since it was last opened.

bool isDirty = !Globals.Application.ActiveWorkbook.Saved;
like image 184
SliverNinja - MSFT Avatar answered Sep 28 '22 03:09

SliverNinja - MSFT