Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Marking Multiple Documents.

Marking Multiple Documents

Written by Allen Wyatt (last updated July 30, 2020)
This tip applies to Word 2007 and 2010


1

Glenn was searching for a way to "place a mark" on a document to indicate that it had been archived. Further, there were many such documents to mark, so a way to load them, add the mark, and save them again was desirable.

There are many different ways that such a task can be achieved. The differences are determined by exactly how the "mark" is placed in a document. Obviously, the word "Archive" (or some such terminology) could be added to a document, but that would affect the actual appearance of the document itself, which is often undesirable.

There is a solution that doesn't involve any visible marks to the document—use document properties. You can set a custom document property that would indicate whether the document has been archived or not. You could later search for the property to determine which files meet your criteria.

The following macro will load all the documents in a directory (and possibly any subdirectories), and either create or set a custom document property indicating that the document has been archived. In this case, the custom property is named Archive, and it is set to a True (Yes) condition.

Public Sub SetArchive()
    Dim bExists As Boolean

    With Application.FileSearch
        .LookIn = "C:\"             ' where to search
        .SearchSubFolders = True    ' search the subfolders
        .FileName = "*.doc"         ' file pattern to match

        ' if more than one match, execute the following code
        If .Execute() > 0 Then
            For i = 1 To .FoundFiles.Count
                ' Open the file
                Documents.Open FileName:=.FoundFiles(i)

                ' Begin document changes

                ' See if the doc variable exists
                bExists = False
                For Each varItem In ActiveDocument.CustomDocumentProperties
                    If varItem.Name = "Archive" Then
                        bExists = True
                        Exit For
                    End If
                Next varItem

                If Not bExists Then
                    ' Add and set document property
                    ActiveDocument.CustomDocumentProperties.Add _
                      Name:="Archive", LinkToContent:=False, _
                      Type:=msoPropertyTypeBoolean, Value:=True
                Else
                    'Already exists, so just set it
                    ActiveDocument.CustomDocumentProperties("Archive") = True
                End If

                ' End document changes

                ' Force document to be saved
                ActiveDocument.Saved = False
                ' Save and close the current document
                ActiveDocument.Close wdSaveChanges
            Next i
        Else
            ' Could not find any DOC files
            MsgBox "No files found."
        End If
    End With
End Sub

To use the macro, just change the directory specification in the fifth line of the macro (starts with .LookIn). Once it is run, the Archive property is created and set in each of the documents. You can view the results by loading one of the files and displaying the properties for the file. How you display the information depends on the version of Word you are using:

  • If you are using Word 2007 click the Office button, then choose Prepare | Properties. Word displays the Document Information Panel at the top of the document. Use the Document Properties drop-down list (top-left corner of the Document Information Panel) to choose Advanced Properties. Word displays the Properties dialog box.
  • If you are using Word 2010 click the File tab of the ribbon and then click Info | Properties | Advanced Properties. Word displays the Properties dialog box.

Regardless of which version of Word you are using, click the Custom tab. Note that the Archive property should be visible in the dialog box.

There is one interesting thing about this macro. Notice that you must "force" the document to be saved by setting the Saved property for the document to False. If you don't do this, then your custom property isn't saved. Why? Apparently Word doesn't recognize a change to a custom property—including adding one—as a reason to save a document. Thus, unless you force the Saved property to False, Word doesn't recognize that any changes have occurred in the document.

If you prefer to not use the custom property approach to marking your archive, you can make some changes to this macro to achieve the desired results. All you need to do is replace the code between the "Begin document changes" and "End document changes" comments with what you want done to the document. For instance, if you want a watermark placed in the document, then simply replace the noted code with code that creates and places the watermark.

Note:

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 (10312) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Marking Multiple Documents.

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

Refreshing PivotTable Data

If you modify the data on which a PivotTable is based, you'll need to refresh the table so it reflects the modified data. ...

Discover More

Taskbar Setting isn't Sticky

Understanding how Excel sets the taskbars upon opening.

Discover More

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Mirroring Documents

Have you ever wanted to have a Word document be accessible through two different folders? Here are several ways you can ...

Discover More

Linking Word Documents

Want to add one document to another document? You can do it by adding links, described in this tip.

Discover More

Recovering Password-Protected Documents

Got a locked document you just need to get into? It may be quite easy (or next to impossible) using the ideas in this tip.

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}] (all 7 characters, in the sequence shown) 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 seven more than 1?

2014-08-26 10:01:07

Rick

Application.FileSearch DOES NOT WORK. It has been abandoned by Microsoft since Office 2007. Trying to use it (in Office 2010) causes
"Run-time Error '5111': This command is not available on this platform."

Please update. Maybe the Dir() function can be used???


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.

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