Automatically Setting Document Properties

Written by Allen Wyatt (last updated August 19, 2023)
This tip applies to Word 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Harwood works for a small town as a building inspector. They need to transform our operations to digital, and the State Library requires that any documents created in programs such as Word include metadata. The problem is that it takes extra time to access the document properties and fill in the required information. The only field that populates automatically is the Author name. Harwood wonders if there is a way to automatically set other document properties, such as file name.

Metadata, as Harwood is discovering, is specified in a Word document through the use of document properties. Word includes some basic document properties you can set and it includes document properties that are set automatically as you work with a document.

You can see both the basic and automatic document properties (and change some of the them) by clicking the File tab of the ribbon and then clicking Info at the left side of the screen. Word displays a whole bunch of information about your document, and at the right side you can see, under the Properties heading, some of the basic document properties that can be changed—such as Title, Tags, and Comments—and some of the automatic ones—such as Words, Total Editing Time, Created, and Last Modified.

If you want to change some of the properties, just click on them and type away. If you want to see more properties, then you can click on the down-arrow at the right of the Properties title and choosing Advanced Properties. Word displays the Properties dialog box. Using the controls in the dialog box you can view and make changes to the properties as desired. (Well, you can make changes to the non-automatic document properties.) You can even define custom document properties to be stored with your document. You can learn how to define custom document properties by referring to this WordTip:

https://tips.net/T12599

If you want more information about document properties directly from Microsoft, this page on their website is helpful:

https://support.microsoft.com/en-gb/office/21d604c2-481e-4379-8e54-1dd4622c6b75

Of course, none of this helps Harwood that much. The reason is that setting the basic document properties or defining custom document properties can be quite labor intensive. You can try setting document properties in a template and then basing new documents on that template, but that doesn't change the need to still massage those properties in the new document.

The only way that I've been able to discover how to remove some of the tedium from setting document properties is to rely on a macro to do the work for me. For instance, the following is a pair of simple macros that create two custom document properties and sets their values:

Sub SetTwoProps()
    Dim sTemp As String
    Dim sMsg As String

    sMsg = "Results of Setting Properties:" & vbCrLf
    sTemp = "   State File Number was"
    If SetProp("StateFileNum", "X23TR7-001") Then
        sTemp = sTemp & " set"
    Else
        sTemp = sTemp & " NOT set"
    End If
    sMsg = sMsg & sTemp & vbCrLf

    sTemp = "   Document Filing Date was"
    If SetProp("DocFileDate", Format(Date, "dd Mmmm YYYY")) Then
        sTemp = sTemp & " set"
    Else
        sTemp = sTemp & " NOT set"
    End If
    sMsg = sMsg & sTemp

    MsgBox sMsg
End Sub
Function SetProp(sPropName As String, sPropValue As String) As Boolean
    Dim bExists As Boolean
    Dim vItem As Variant

    SetProp = False
    On Error GoTo ExitFunc

    ' See if document properties already exist
    bExists = False
    For Each vItem In ActiveDocument.CustomDocumentProperties
        If vItem.Name = sPropName Then
            bExists = True
            Exit For
        End If
    Next vItem

    ' Create document property if it doesn't exist
    ' If it does exist, just set its value
    If Not bExists Then
        ActiveDocument.CustomDocumentProperties.Add _
          Name:=sPropName, LinkToContent:=False, _
          Type:=msoPropertyTypeString, Value:=sPropValue
    Else
        ActiveDocument.CustomDocumentProperties(sPropName) = _
          sPropValue
    End If

    ' Made it through successfully
    SetProp = True
ExitFunc:
End Function

To use these macros, you run the SetTwoProps macro to specify the property names, the values, and to display a results message (put together in the sMsg variable). The macro calls the SetProp function, which actually does the "heavy lifting" of setting the document property. It checks to see if the property already exists and, if it doesn't, it creates the property. It returns True or False, depending on whether the property setting was successful or not.

Harwood could use a macro similar to SetTwoProps to set the document properties necessary to satisfy the State Library. When you first create a document (or before you send the document off to the State Library) you could then run the macro to make sure the document properties are set the way they need to be set.

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 (11418) applies to Microsoft Word 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.

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

Controlling Scroll Bars

Scroll bars are helpful if you have a document that won't fit entirely within the program window. Here's how to turn off ...

Discover More

Inserting Text with a Macro

Need to have your macro insert a bit of text into your document? It's easy to do using the TypeText method.

Discover More

Understanding Master and Subdocuments

Most people use Word to create regular documents that you edit, view, and print. The program also allows you to create a ...

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)

Blocking the First Sentence from File Info

When you save a file, the information from the start of the file is saved in the properties for the document and can be ...

Discover More

Embedding Your Phone Number in a Document

One way you can designate your responsibility for a document is to add your phone number to it. There is no need to add ...

Discover More

Using Document Properties to Ensure Consistent References

If you need to refer to the same information over and over in a document, you may be interested in using custom document ...

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 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.