Microsoft Office Forums Batch Comparing Multiple Word Files

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 10-01-2019, 05:48 AM
scienceguy scienceguy is offline Batch Comparing Multiple Word Files Windows 10 Batch Comparing Multiple Word Files Office 2016
Batch Comparing Multiple Word Files
Join Date: Feb 2019
Posts: 23
scienceguy is on a distinguished road
Default Batch Comparing Multiple Word Files


I am trying to write an application, whereby Word vba will compare Word files in one folder (original version) with the corresponding files in another folder (updated or revised version) and show the track changes. The application would process one file at a time and save the tracked changed file as "original_file_name_tracked.docx". In the end, the application would have generated a tracked change version of each set of files (original versus revised).

To accomplish this, I recorded a macro in Word vba that processed the first file. I then modified the code to work on an entire folder, one file at a time. Unfortunately, I am getting a run-time error 4160 (Bad File Name). I went back to the original recorded macro and ran it (without any modifications on my part), and it also throws the same error. If any one has any suggestions, I would appreciate it. Below is my code for processing a folder.

Thank you in advance for any help!


Sub trackMe()
' trackMe Macro
Dim strFolderOriginal As String, strFolderUpdated As String
Dim strfile As String
Dim tempFileName As String

With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = -1 Then
        strFolderOriginal = .SelectedItems(1)
    End If
End With
If strFolderOriginal = "" Then
    Exit Sub
End If

With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = -1 Then
        strFolderUpdated = .SelectedItems(1)
    End If
End With
If strFolderUpdated = "" Then
    Exit Sub
End If

strfile = Dir(strFolderOriginal & "\*.doc", vbNormal)

While strfile <> ""

    tempFileName = stripFileName(strfile) 'remove file extension
    ChangeFileOpenDirectory strFolderOriginal & "\"
    ChangeFileOpenDirectory strFolderUpdated & "\"
    Application.CompareDocuments OriginalDocument:=Documents( _
        strfile) _
        , RevisedDocument:=Documents( _
        strfile) _
        , Destination:=wdCompareDestinationOriginal, Granularity:= _
        wdGranularityCharLevel, CompareFormatting:=True, CompareCaseChanges:=True _
        , CompareWhitespace:=True, CompareTables:=True, CompareHeaders:=True, _
        CompareFootnotes:=True, CompareTextboxes:=True, CompareFields:=True, _
        CompareComments:=True, CompareMoves:=True, RevisedAuthor:="Author", _
    ChangeFileOpenDirectory strFolderOriginal & "\"
    ActiveDocument.SaveAs2 FileName:= _
        tempFileName & "_tracked.docx" _
        , FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
        AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
        :=False, SaveAsAOCELetter:=False, CompatibilityMode:=12
    strfile = Dir()

MsgBox "Finished"

End Sub
Function stripFileName(strFilename As String) As String
'used to remove file extension

Dim k As Integer

For k = Len(strFilename) To 1 Step -1
    If Mid(strFilename, k, 1) = "." Then
        stripFileName = Mid(strFilename, 1, k - 1)
        Exit For
    End If
Next k

End Function

Reply With Quote

batch processing, track changes

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
batch extract all tables in multiple word documents ZaidaBa Word Tables 3 05-08-2017 10:22 PM
Batch Comparing Multiple Word Files Batch create word files with link to changing excel hannes.ledegen Mail Merge 8 04-07-2016 01:22 AM
Batch Comparing Multiple Word Files Batch add suffix to PDF files in folder Dave T Windows 2 03-01-2016 08:07 PM
Remove Compatibility Mode on DOCX files (batch) w64bit Word 17 02-01-2015 06:02 AM
Macro to format additions deletions when Comparing Files Alphacsulb Word VBA 0 08-19-2013 03:03 PM

All times are GMT -7. The time now is 03:24 PM.

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