Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-23-2015, 09:19 PM
wwballar42 wwballar42 is offline Changing custom properties in multiple word documents Windows 7 32bit Changing custom properties in multiple word documents Office 2010 32bit
Novice
Changing custom properties in multiple word documents
 
Join Date: Sep 2015
Posts: 2
wwballar42 is on a distinguished road
Default 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.
Attached Images
File Type: png Screen Shot 2015-09-23 at 9.09.47 PM.png (30.4 KB, 32 views)
File Type: png Screen Shot 2015-09-23 at 9.13.47 PM.png (48.8 KB, 32 views)
File Type: png Screen Shot 2015-09-23 at 9.13.54 PM.png (50.6 KB, 31 views)
Reply With Quote
  #2  
Old 09-24-2015, 12:22 AM
gmayor's Avatar
gmayor gmayor is offline Changing custom properties in multiple word documents Windows 7 64bit Changing custom properties in multiple word documents Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 09-25-2015, 08:52 AM
wwballar42 wwballar42 is offline Changing custom properties in multiple word documents Windows 7 32bit Changing custom properties in multiple word documents Office 2010 32bit
Novice
Changing custom properties in multiple word documents
 
Join Date: Sep 2015
Posts: 2
wwballar42 is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 09-25-2015, 05:01 PM
macropod's Avatar
macropod macropod is offline Changing custom properties in multiple word documents Windows 7 64bit Changing custom properties in multiple word documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 09-25-2015, 07:13 PM
gmaxey gmaxey is offline Changing custom properties in multiple word documents Windows 7 32bit Changing custom properties in multiple word documents Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 09-25-2015, 07:38 PM
macropod's Avatar
macropod macropod is offline Changing custom properties in multiple word documents Windows 7 64bit Changing custom properties in multiple word documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 06-22-2020, 08:53 PM
gmayor's Avatar
gmayor gmayor is offline Changing custom properties in multiple word documents Windows 10 Changing custom properties in multiple word documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
P.S. As this issue may arise again, I have now updated the add-in to version 4.3 to force the save in the Custom Process code so that any process which does not allow Word to see a change, will actually force the document to be saved regardless.
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.
Reply With Quote
Reply

Thread Tools
Display Modes


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
Changing custom properties in multiple word documents Searching with Custom Properties jpb103 Word VBA 6 05-30-2014 07:08 AM
Changing custom properties in multiple word documents 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft