我是英语系的教授,我的作文学生经常写多份论文草稿。我使用 Word 2010 来跟踪他们的更改。
我在另一个站点(位于此处)上发现了 VBA 代码。我创建了一个新宏。它正确提示我输入基本文件夹、新文件夹和比较文件夹,但输出为空。
我在基本文件夹和新文件夹中都有相同名称的文件,并以 .doc 格式保存。我还将 Word 中的信任中心选项设置为 1) 启用所有宏和 2) 信任对 VBA 项目对象模型的访问。
Sub CompareAllFiles()
Dim strFolderA As String
Dim strFolderB As String
Dim strFolderC As String
Dim strFileSpec As String
Dim strFileName As String
Dim objDocA As Word.Document
Dim objDocB As Word.Document
Dim objDocC As Word.Document
strFolderA = InputBox("Enter path to base documents:")
strFolderB = InputBox("Enter path to new documents:")
strFolderC = InputBox("Enter path for document comparisons to be saved:")
strFileSpec = "*.doc"
strFileName = Dir(strFolderA & strFileSpec)
Do While strFileName <> vbNullString
Set objDocA = Documents.Open(strFolderA & strFileName)
Set objDocB = Documents.Open(strFolderB & strFileName)
Application.CompareDocuments _
OriginalDocument:=objDocA, _
RevisedDocument:=objDocB, _
Destination:=wdCompareDestinationNew
objDocA.Close
objDocB.Close
Set objDocC = ActiveDocument
objDocC.SaveAs FileName:=strFolderC & strFileName
objDocC.Close SaveChanges:=False
strFileName = Dir
Loop
Set objDocA = Nothing
Set objDocB = Nothing
End Sub