Accessing the Dirty Flag

by Allen Wyatt
(last updated February 7, 2015)

5

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

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

MORE FROM ALLEN

Preventing the Left Margin of a Footer from Moving

When you print a document, does the position of the page footer seem to move left and right? This could have to do with how ...

Discover More

Returning a Worksheet Name

Need to know the name of the current worksheet? You can use the CELL function as the basis for finding this information and ...

Discover More

Changing the Characteristics of the Recycle Bin

Windows allows you to easily configure the properties associated with the Recycle Bin. This tip provides an overview of what ...

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)

Converting Inches to Points

Typographical measurements are often expressed in points. There are several formatting settings that, when accessed through a ...

Discover More

Temporarily Changing the Printer in a Macro

You can use a macro to print to any printer you have defined in Windows. It is good practice, if you are changing which ...

Discover More

Cleaning Up Text in a Macro

Need to remove extraneous characters from a text string? VBA makes it easy through the CleanString method, described in this ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 6 + 0?

2015-10-09 12:22:43

donna

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

Dr_Tek

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
Subscribe

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.