Loop comparison macro

橙三吉。 提交于 2019-12-02 12:39:59

not entirely sure what you mean but you can select a batch of files to operate on using using the built-in file dialogs.

An example is:

Sub Example()
    Dim item, templateDoc As Document, compareDoc As Document

    'Get template file
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .Title = "Select template"
        If .Show = 0 Then Exit Sub
        Set compareDoc = Documents.Open(.SelectedItems(1))
    End With

    'Get files to batch process
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .Title = "Select files to compare"
        If .Show = 0 Then Exit Sub
        For Each item In .SelectedItems
            'Do some stuff
            Set compareDoc = Documents.Open(item)
            CompareDocs templateDoc, compareDoc
            compareDoc.Close
        Next
    End With

End Sub
Sub CompareDocs(templateDoc As Document, compareDoc As Document)
    Application.CompareDocuments _
            OriginalDocument:=templateDoc, _
            RevisedDocument:=compareDoc, _
            Destination:=wdCompareDestinationNew, _
            Granularity:=wdGranularityWordLevel, _
            CompareFormatting:=False, _
            CompareCaseChanges:=True, _
            CompareWhitespace:=False, _
            CompareTables:=True, _
            CompareHeaders:=True, _
            CompareFootnotes:=True, _
            CompareTextboxes:=True, _
            CompareFields:=True, _
            CompareComments:=True, _
            CompareMoves:=False, _
            RevisedAuthor:="UOB", _
            IgnoreAllComparisonWarnings:=False
    ActiveWindow.ShowSourceDocuments = wdShowSourceDocumentsBoth
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!