Accessing the Dirty Flag

by Allen Wyatt
(last updated August 12, 2020)


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, 2013, 2016, 2019, and Word in Office 365.

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. ...


Inserting the User's Initials

One of the pieces of information tracked by Word are your name and initials. You can insert your initials by using the ...

Discover More

Sorting by Fill Color

Sorting data in a worksheet is easy, unless you want to sort by the color used to fill a range of cells. There are ways ...

Discover More

ScreenTips without Hyperlinks

ScreenTips can be a helpful feature in some documents, but adding them also means you need to add a hyperlink. Here's a ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Determining if Overtype Mode is Active

Your macro may need to determine if the user has overtype mode turned on. You can find out the overtype status easily by ...

Discover More

Using Message Boxes

If your macro needs to communicate with a user, one simple way to do it is to use a message box. Here's how to use this ...

Discover More

Creating a Document Font List

If you want a list of all the fonts used in a document, the answer isn't as simple as you may think. This tip uses macros ...

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 six 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.