View Single Post
 
Old 04-23-2024, 02:09 AM
anmalogo anmalogo is offline Windows 11 Office 2021
Novice
 
Join Date: Apr 2024
Posts: 8
anmalogo is on a distinguished road
Default Help with Excel macro to extract all custom properties of Word Document to later mass update

Hello All,

Currently, I'm trying to develop an Excel macro, to read all the Word files in a folder and sub folder, and populate all the custom properties present in those documents. Later, the idea is to use that Excel sheet (second macro) to mass update the custom properties in the same files.

Here is the code I currently have. This code will list in column A the file path, and in column b, the file name. All custom properties from the Word document are missing. I don't know how to get them. Any ideas?. 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