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, 42 views)
File Type: png Screen Shot 2015-09-23 at 9.13.47 PM.png (48.8 KB, 43 views)
File Type: png Screen Shot 2015-09-23 at 9.13.54 PM.png (50.6 KB, 41 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,105
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,963
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,429
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,963
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,105
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
  #8  
Old 04-23-2024, 01:15 AM
anmalogo anmalogo is offline Changing custom properties in multiple word documents Windows 11 Changing custom properties in multiple word documents Office 2021
Novice
 
Join Date: Apr 2024
Posts: 6
anmalogo is on a distinguished road
Default Can you please share the macro?

Quote:
Originally Posted by wwballar42 View Post
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.

Hello wwballar42,

I have the same issue. A lot of documents all of them with the same properties, and I would like to mass update the properties for all of them.

What I'm thinking is to create an Excel macro to first list all the custom properties from all the document which in a folder and sub-folders, after all the custom properties are displayed in the Excel Sheet, modify them and mass update.

Currently what I have is a Macro to read all files and list in column 1 the file path, and in column 2, the file name. I'm currently not able to get the custom properties .

Here is the Excel VBA code mentioned above, in case someone knows how to do it.

Thanks in advance for your help.

HTML Code:
Sub getfiles()
    'Get the files name from Folder and Subfolder
    Dim oFSO As Object
    Dim oFolder As Object
    Dim oFile As Object, sf
    Dim i As Integer, colFolders As New Collection, ws As Worksheet
    Dim selectedFolder As Variant
    Dim fd As FileDialog
    
    Set ws = ActiveSheet
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    'Prompt user to select a folder
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    
    With fd
        .Title = "Select Folder"
        .AllowMultiSelect = False
        If .Show = -1 Then
            selectedFolder = .SelectedItems(1)
        Else
            MsgBox "No folder selected. Operation aborted."
            Exit Sub
        End If
    End With
    
    Set oFolder = oFSO.getfolder(selectedFolder)
    
    colFolders.Add oFolder          'start with this folder
    
    Do While colFolders.Count > 0      'process all folders
        Set oFolder = colFolders(1)    'get a folder to process
        colFolders.Remove 1            'remove item at index 1
        
        For Each oFile In oFolder.Files
            If oFile.DateLastModified > Now - 7 Then
                ws.Cells(i + 1, 1) = oFolder.Path
                ws.Cells(i + 1, 2) = oFile.Name
                'ws.Cells(i + 1, 3) = oFile.DateLastModified
                i = i + 1
            End If
        Next oFile
        
        'add any subfolders to the collection for processing
        For Each sf In oFolder.subfolders
            colFolders.Add sf
        Next sf
    Loop
End Sub
Reply With Quote
  #9  
Old 04-23-2024, 03:59 PM
Guessed's Avatar
Guessed Guessed is offline Changing custom properties in multiple word documents Windows 10 Changing custom properties in multiple word documents Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You probably need to open each doc to get at the custom properties.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #10  
Old Yesterday, 05:43 AM
anmalogo anmalogo is offline Changing custom properties in multiple word documents Windows 11 Changing custom properties in multiple word documents Office 2021
Novice
 
Join Date: Apr 2024
Posts: 6
anmalogo is on a distinguished road
Default

Hello all, first of all the reason why I cannot see "all" the document properties, is because the missing properties were created via SharePoint. The document gets created then uploaded in Sharepoint, I think those attributes/properties (in ShapePoint) are stored probably in a XML file embedded in the document. Don't know how to extracted, to later list them via VBA.
Any ideas?.
Thanks.
Reply With Quote
Reply



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 08:42 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