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

Superscripts in Custom Formats

When you create custom formats for your data, Excel provides quite a few ways you can make that data look just as you ...

Discover More

Creating a Drawing Object

Creating simple drawing objects is easy in Excel. All you need to do is use the tools made available on the Drawing toolbar.

Discover More

Deleting a User Account

Windows allows you to define individual user accounts for different people using a computer. If a person no longer needs ...

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)

Controlling Document Properties

Word keeps track of quite a bit of document-related information that it refers to as "properties." Here's how to control ...

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

Changing Lots of Title Properties

Word maintains a collection of descriptive properties for each document you create. One of these properties is the Title ...

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 8 + 5?

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.