Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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: Copying Custom Properties.

Copying Custom Properties

Written by Allen Wyatt (last updated April 21, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

Custom document properties are a great way to store unique information that is associated with a document. For instance, you may have a company-assigned document number that needs to be stored with a document. A custom property fits the bill quite nicely for this purpose.

As you add custom properties to a document, you may start wondering if there is an easy way to copy them from one document to another. Unfortunately, there is no way to do this. (In my estimation, this capability would make a fine addition to the Organizer.) You can, however, create a macro that will do the copying for you. The following macro will do just that:

Sub CopyDocProps()
    Dim dp() As DocumentProperty
    Dim CustomPropCount As Integer
    Dim i As Integer
    Dim iResponse As Integer

    If Windows.Count > 2 Then
        MsgBox "There are more than two windows. Please " & _
          "close the others and re-run the macro.", , _
          "Too many windows"
        Exit Sub
    End If

    On Error GoTo Err_Handler

    iResponse = MsgBox("Are you currently in the source document?", _
      vbYesNoCancel, "Copy Custom Properties")

    If iResponse = vbNo Then Application.Run MacroName:="NextWindow"

    CustomPropCount = ActiveDocument.CustomDocumentProperties.Count
    ReDim dp(1 To CustomPropCount)

    For i = 1 To CustomPropCount
        Set dp(i) = ActiveDocument.CustomDocumentProperties(i)
    Next i

    Application.Run MacroName:="NextWindow"

    For i = 1 To CustomPropCount
        If dp(i).LinkToContent = True Then
            ActiveDocument.CustomDocumentProperties.Add _
              Name:=dp(i).Name, _
              LinkToContent:=True, _
              Value:=dp(i).Value, _
              Type:=dp(i).Type, _
              LinkSource:=dp(i).LinkSource
        Else
            ActiveDocument.CustomDocumentProperties.Add _
              Name:=dp(i).Name, _
              LinkToContent:=False, _
              Value:=dp(i).Value, _
              Type:=dp(i).Type
        End If
    Next i

    MsgBox "The properties have been copied."
    Exit Sub

Err_Handler:
    ' if Word raises an error, then allow the user
    ' to update the custom document property
    
    iResponse = MsgBox("The custom document property (" & _
      dp(i).Name & ") already exists." & vbCrLf & vbCrLf & _
      "Do you want to update the value?", vbYesNoCancel, _
      "Copy Custom Properties")

    Select Case iResponse
        Case vbCancel
            End
        Case vbYes
            ActiveDocument.CustomDocumentProperties(dp(i).Name).Value _
              = dp(i).Value
            Resume Next
        Case vbNo
            Resume Next
    End Select
End Sub

This code is an example of how to copy custom properties, but it is not bulletproof. For instance, it does not check to see if there are actually any custom properties in the source document; it just assumes that there are. Such coding could be easily added, however.

In order to use the macro, make sure that you have only the source and target documents open, and you should only have one window open per document. When the macro is finished, you will need to save the target document.

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 (11671) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Copying Custom Properties.

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

Using the MROUND Worksheet Function

If you want to round a value to some multiple of a whole number, you'll want to become familiar with the MROUND function. ...

Discover More

Deleting Worksheets in a Macro

Processing workbooks using a macro often involves the possible creation and subsequent deletion of worksheets. When it ...

Discover More

Automatic Blank Pages at the End of a Section

If you want to have a blank page at the end of a document section, you can insert one manually or you can use the ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Inserting a File Name without an Extension

Sometimes you might like to insert a file name into your document without including the file extension. The FILENAME ...

Discover More

Modifying the Backup Copy File Name

Backup files, created automatically by Word, have the filename extension WBK and start with the words "Backup of." If you ...

Discover More

Converting Many DOC Files to DOCX

Need to convert a bunch of old DOC files to the newer DOCX format? Word doesn't provide the capability to convert a bunch ...

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 four minus 0?

2018-06-09 15:33:39

Dr. Bartolo

I tried to use this macro but it crashes with the message "runtime error 9 subscript out of range" when it gets to the error handling section (it should display a message box). Is this a bug in the code or my machine? Anyone have any ideas?


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.