#1
|
|||
|
|||
Changing custom properties in multiple word documents
Hello,
I am trying to see a way where I can have the custom properties defined and then have a macro to change other multiple word documents. These custom properties are the same in all word documents, and I think its a bit much to go into each word document and change the properties. I am hoping there is a better solution to this. I will attach the custom properties that are in the word document. Hoping you could help me create a macro where all these custom properties can be updated once for multiple word documents. Thanks so much for your help. |
#2
|
||||
|
||||
The following macro function when used in conjunction with http://www.gmayor.com/document_batch_processes.htm as a custom process will add the custom docproperty 'Department' to either the current document or a folder full of documents (including sub folders if you wish). If the property is already present it will be updated with the value entered, which from your illustrations appears to be 'Money'
You can change the Constants to reflect any custom property name, value or type Code:
Option Explicit Function DocProp(oDoc As Document) As Boolean Dim oProp As DocumentProperty Dim bProp As Boolean Const strName As String = "Department" Const strValue As String = "Money" Const lngType As Long = 4 'Text On Error GoTo err_Handler bProp = False For Each oProp In oDoc.CustomDocumentProperties If oProp.name = strName Then oProp.Value = strValue bProp = True Exit For End If Next oProp If Not bProp Then oDoc.CustomDocumentProperties.Add _ name:=strName, _ LinkToContent:=False, _ Value:=strValue, _ Type:=lngType End If DocProp = True lbl_Exit: Exit Function err_Handler: DocProp = False Resume lbl_Exit End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
I don't think the code does exactly what I am looking for. What I am looking for is a way to update multiple documents with the same properties all at once. Lets say I update one document, but have 4 other documents that I have reviewed, but do not want to individually update one by one. Is there a way where all 4 documents can be updated at the same time?
I was hoping there was a code that when entered, changes the custom properties, like title, author, company, and other custom properties that I have defined in the attachment. For example, date completed, version number, approved by, department, and classification. |
#4
|
||||
|
||||
There is no way to link the custom document properties in one document to custom document properties in another. If all the documents are in the same folder (and there are no other documents in that folder), Graham's code can be used to propagate the custom document properties that are input into the macro to all of those documents. If you need to replicate the custom document properties in the activedocument to just a selection of other documents, that can be done via hard-coding those documents' names into a macro or by providing a dialogue box one can use to select the documents. You need to specify precisely what your requirements are.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Paul, unless Graham has changed his code, his works the same as mine. "(...and there are not other documents in that folder") shouldn't matter. The function will simply error and the return a false value for any document in the folder that fails to process.
|
#6
|
||||
|
||||
Hi Greg,
Graham's code in post #2 above adds the properties to any documents that don't have them so, in that sense, it does matter. Graham says as much. That wasn't the main thrust of my post, though, which was to address the OP's desire to dynamically update the properties in one or more related documents when the properties in one of them is changed. Word provides no means of doing this, though there are ways of doing it automatically (e.g. via a Document_Close macro), provided certain conditions are met.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
||||
|
||||
This is an old thread, but a user has reported that the macro I posted doesn't actually work, at least not with the latest versions of my (or Greg's) add-ins. The reason appears to be that simply changing the document property with the posted code is not seen by the document as something that needs to be saved, and so it isn't. So to use it you need to change the code to flag it as unsaved as shown below.
Code:
Option Explicit Function DocProp(oDoc As Document) As Boolean Dim oProp As DocumentProperty Dim bProp As Boolean Const strName As String = "Department" Const strValue As String = "Money" Const lngType As Long = 4 'Text On Error GoTo err_Handler bProp = False For Each oProp In oDoc.CustomDocumentProperties If oProp.Name = strName Then oProp.value = strValue bProp = True Exit For End If Next oProp If Not bProp Then oDoc.CustomDocumentProperties.Add _ Name:=strName, _ LinkToContent:=False, _ value:=strValue, _ Type:=lngType End If For Each oProp In oDoc.CustomDocumentProperties If oProp.Name = strName Then oProp.value = strValue Exit For End If Next oProp oDoc.Saved = False DocProp = True lbl_Exit: Exit Function err_Handler: DocProp = False Resume lbl_Exit End Function https://www.gmayor.com/document_batch_processes.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 06-23-2020 at 12:21 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add custom doc properties in "Doc properties control" | eazysnatch | Word | 2 | 09-13-2017 08:08 PM |
Searching with Custom Properties | jpb103 | Word VBA | 6 | 05-30-2014 07:08 AM |
Changing Default Author on New Word 2013 Documents | chaplaindoug | Word | 1 | 01-09-2014 12:00 PM |
Custom Properties | b-baker | Word | 1 | 03-01-2012 01:15 AM |
Looping though Custom Properties in VBA | suekay | Misc | 0 | 05-19-2006 06:10 AM |