Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-08-2023, 04:51 AM
eyoung eyoung is offline Batch compare word documents with a summary report Windows 11 Batch compare word documents with a summary report Office 2016
Novice
Batch compare word documents with a summary report
 
Join Date: May 2023
Posts: 2
eyoung is on a distinguished road
Default Batch compare word documents with a summary report

I am wanting to write a VBA script that compares a set of documents in one folder with a set of documents in a second folder (they have the same names, generated at different times). The tracked changes comparison is then saved to a third folder. My intention is then to loop through these tracked changes documents and create a summary report that has two tables: 1) Table that specifies the name of the file and whether there were changes or not. 2) Detailed table that specified revisions.



I have the first part of the VBA working, which loops through all the files and successfully saves the tracked changes version.

I have no idea where to even begin with getting the second part (the summary report) up and working.

Code:
Sub Compare()
 Dim wd As Word.Application
 Dim odoc As Word.Document
 Dim rdoc As Word.Document
 Dim strOPath As String
 Dim strRPath As String

 Dim strCPath As String
 Dim strORTFfile As String
 Dim ofiles() As String
 Dim i As Integer
 Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        .title = "Select the folder that contains the original files."
        If .Show = -1 Then
            strOPath = .SelectedItems(1) & Application.PathSeparator
        Else
            MsgBox "You did not select a folder."
            Exit Sub
        End If
    End With
    With fd
        .title = "Select the folder that contains the revised files."
        If .Show = -1 Then
            strRPath = .SelectedItems(1) & Application.PathSeparator
        Else
            MsgBox "You did not select a folder."
            Exit Sub
        End If
    End With
    With fd
        .title = "Select the folder where the comparison files will be saved."
        If .Show = -1 Then
            strCPath = .SelectedItems(1) & Application.PathSeparator
        Else
            MsgBox "You did not select a folder."
            Exit Sub
        End If
    End With
 
 Set wd = GetObject(, "Word.Application")
 If wd Is Nothing Then
 Set wd = CreateObject("Word.Application")
 End If
 ReDim Preserve ofiles(0)
 strORTFfile = Dir(strOPath & "\" & ("*.rtf"), vbNormal)

 Do While strORTFfile <> Empty
 ReDim Preserve ofiles(UBound(ofiles) + 1)
 ofiles(UBound(ofiles)) = strORTFfile
 strORTFfile = Dir
 Loop
 
 For i = 1 To UBound(ofiles)
 If Dir(strRPath & "\" & ofiles(i)) <> Empty Then
 Set odoc = wd.Documents.Open(strOPath & "\" & ofiles(i))
 Set rdoc = wd.Documents.Open(strRPath & "\" & ofiles(i))
 Set ndoc = Application.CompareDocuments(OriginalDocument:=odoc, _
 RevisedDocument:=rdoc, _
 Destination:=wdCompareDestinationNew, _
 Granularity:=wdGranularityWordLevel, _
 CompareFormatting:=True, _
 CompareCaseChanges:=True, _
 CompareWhitespace:=True, _
 CompareTables:=True, _
 CompareHeaders:=True, _
 CompareFootnotes:=False, _
 CompareTextboxes:=True, _
 CompareFields:=True, _
 CompareComments:=True, _
 CompareMoves:=True, _
 RevisedAuthor:="USERNAME", _
 IgnoreAllComparisonWarnings:=False)

 ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsNone
 ActiveWindow.Visible = False
 ofiles(i) = Replace(ofiles(i), Chr(13), "")
 ndoc.SaveAs2 FileName:=strCPath & "\" & ofiles(i), _
 FileFormat:=wdFormatRTF, LockComments:=False, _
 Password:="", AddToRecentFiles:=True, WritePassword:="", _
 ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
 SaveNativePictureFormat:=False, SaveFormsData:=False, _
 SaveAsAOCELetter:=False, CompatibilityMode:=0
 odoc.Close SaveChanges = False
 rdoc.Close SaveChanges = False
 ndoc.Close SaveChanges = False
 End If
 
 Next
 

End Sub
Reply With Quote
 

Tags
batch processing, compare documents, summary tasks



Similar Threads
Thread Thread Starter Forum Replies Last Post
batch compare word file maimi23 Word VBA 1 09-23-2021 04:21 AM
Batch compare word documents with a summary report Batch merging of Word documents Harry Gateaux Word VBA 6 11-19-2020 09:58 AM
Batch Editing Word documents sakhtar6 Word VBA 6 03-02-2020 02:49 PM
Batch compare word documents with a summary report Batch create Word documents cdfj Word VBA 6 11-07-2012 01:03 PM
Batch compare word documents with a summary report Can you compare two word documents? (Automatically) admin4ever Word 2 05-17-2011 09:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:29 AM.


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