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 intResponse 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 intResponse = MsgBox("Are you currently in the source document?", _ vbYesNoCancel, "Copy Custom Properties") If intResponse = 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 intResponse = 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 Response 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:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1340) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Copying Custom Properties.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
At some point you may want to insert one Word document inside another Word document. An easy way to do this is to use the ...
Discover MoreDon't want Word to load up your HTML documents as formatted text? There are a couple of ways you can instruct Word to be ...
Discover MoreWord has a feature called AutoRecover that helps you when Word or Windows crashes. If your Normal template gets messed up ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-02-04 22:08:29
Georgia Abbott
Thanks so much, exactly what I wanted. I've never used Macros in Word and I still got this going first try. You're a treasure!
2019-08-20 06:17:11
Simon Rouse
I've just come across this and it's exactly what I wanted, thanks so much. I was thinking about writing something like this, but it would have taken time and probably not been as elegant as this. I've added a a call to my UpdateAllFields routine at the end, and it works like a dream
2019-03-19 18:43:21
Gerda
It works perfectly if there are no custom properties with those names, however when they already exist, they do not update even after it asks "do you want to update the value?"
2018-06-25 22:27:25
John Humphrey
OMG, this is BRILLIANT!!!! I can't believe how much time this is gonna save. I know the thread is old, but the utility is timeless!!! Thank you so much!
2016-10-14 17:49:54
Dino Philopoulos
Beautiful, worked like a charm and saved me lots of time.
2016-09-23 07:45:00
Eric Pigal
Congratulations for those hints/tips!
This is the 2nd time I leverage some source code from you.
I'm quite impressed with simplicity, quality and clarity.
Many thanks.
2016-08-12 05:12:17
Fred Carruthers
What a great little macro. For others I managed fixed the wee bug that stops the script if an entry already exists. Change the line:
'Select Case Response' to
'Select Case intResponse'
It now works a treat saving me a stack of time.
2016-05-24 08:54:57
Thomas
Thanks for the script. There is just one problem that the script stops if there is an entry already available. So better clear all custom values in the target, before starting the script.
Thanks a lot!
2015-04-28 13:58:19
Paul B
Thanks Allen. This indeed should be in the MS Word functionality. Without this, there is no 100% transportability.
This worked for me as well. It's now in my Normal.dot library.
2014-11-03 20:00:48
Mike Thompson
Many thanks for this :-) Exactly what I needed, and I can confirm this works for Word 2013.
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments