Accessing the Dirty Flag

by Allen Wyatt
(last updated June 3, 2019)


Jerry has made a macro for version control that asks the user if she wants to save the document with a new version number. It runs automatically when a document is opened. However, Jerry would prefer to let the macro run only when a document is actually changed or altered in any way by the user. He wonders if there is an event that registers when a document is actually edited? Or is there, perhaps, a property that registers whether a document has been changed?

There is no event, but there is a property. What you want to do is check the Saved property of whatever document you are processing. If the property is True, then there have been no changes. If the property is False, then there are unsaved changes. (In other words, the True of False state of the Saved property indicates whether the document has been saved or not.)

If you want to do your prompting about a version number when the user is closing the document, then you'll want to work with the Document_Close event handler. Modify the event handler so that you check the state of the Saved property, in this way:

Private Sub Document_Close()
    If Not ActiveDocument.Saved Then
        ' Check to see if version should be updated
    End If
End Sub

You'll need, of course, to replace the comment with your specific code for handling what should occur relative to a version number. The Save method is used to save the document under the current name; if you wanted to save it under a new name you would instead use the SaveAs method.

There is one caveat to remember: It is possible for the Saved property to be set to False even though the user didn't actually make a change in the document. For instance, if there are fields in the document and the fields get automatically updated, then the Saved property is set to False. There are a few other situations where the property is changed, as well, but the Saved property is the most accurate way available to determine whether a document as actually changed or not.


If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13368) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Understanding the Normalize Text Command

Word includes tons of internal commands that you can access as you customize your system. One of these is the Normalize ...

Discover More

Replacing Dashes with Periods

Replacing one character in a text value with another character is easy. All you need to do is use the SUBSTITUTE ...

Discover More

Deleting a Macro

ScreenTips can appear with or without shortcut keys displayed in them. Here's how to control whether they appear or not.

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Determining Differences Between Dates

Do you need to do some simple math using dates in a your macro? One of the easy functions you can use is the DateDiff ...

Discover More

Calculated Dates

Word makes it easy to insert today's date in a document, but not as easy to insert a date X number of days in the future. ...

Discover More

Moving to the Start or End of the Real Document

The main body of your text is only one part of what makes up the entire document. Documents can consist of other ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 3?

2019-01-28 16:36:03

Steven R

FYI: The 'Saved' property of the ActiveDocument object is in fact a Read/WRITE Boolean object. To mark a document as 'saved' after your macro works on it, simply add the statement:
ActiveDocument.Saved = True
as the last statement in your macro. This will prevent the 'Save Document' dialog from appearing when you close the document after the macro runs. QED

2015-10-09 12:22:43


My college is using something called a "thin client" for the students. I think this is affecting the Word properties, it says document has never been saved, or was created months before the student started it, or was modified but editing time was 0 minutes. I don't know anything about thin clients so don't know what to make of these results

2015-07-06 09:17:04

Rick G.

One of the properties in all Word docs keeps track of the Date & Time that the doc was Last Printed. (In Word 2010 you can see this property by clicking on the "File" tab.) So anytime you print a doc, this property is automatically updated. That sets the "dirty flag" saying the doc was modified (because the property was modified). There is no option to turn off updating that property when you print the doc. (If you don't save the doc after printing it, that property retains the previous time & date printed.)

2015-02-22 20:53:36

Paulo Almeida

My experience is like Jay Scheuerman says. Before MS Word 2007, that functions works well, but since MS Word 2007, it doesn't work well!

2015-02-09 11:20:40


How do you remove a dirty flag from a document that does not have a macro (nor do you want one).

We have PRs that we reuse and save with the new PR # when they are from the same vendor. They often pick up a dirty flag although they were initially saved. We want to retain the original
"Date modified", so we do not want to save them when they are reopened. Also, we have found that saving them again does not remove the flag.

2015-02-09 09:34:16

Jay Scheuerman

On a related vein, is there a way to stop Word from seeing the print function as a change? If I merely open, print, and close one of my typical work documents, Word always asks if I want to save changes. Shouldn't setting the printing options for "Update fields before printing" and "Update linked data before printing" to off keep this from happening?

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.