我是英语系教授,我的作文学生经常写他们的散文的多个草稿。我使用Word 2010来跟踪他们的更改。比较多对文档
我在另一个网站上发现了VBA代码(位于here)。我创建了一个新的宏。它会正确提示我是否有基本文件夹,新文件夹和比较文件夹,但输出为空。
我在基本文件夹和新文件夹中命名相同并以.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
谢谢您的建议!我感谢你的时间。 :) –