Showing posts with label Compare Word Documents. Show all posts
Showing posts with label Compare Word Documents. Show all posts

Monday, January 30, 2012

Compare Word Documents with Headers and Footers using VBA

How to Compare Word Documents Programatically using Word VBA

Word Documents are everywhere .. proposals, tenders, notes, technical papers. In many cases there are more than one authors and more than five reviewers. There is a devil in everyone which comes out when reviewing the document. Suggest some changes.. boldface  some text, markup some paragraph and screw the document. If you are  the author it is your responsibility to ensure that the changes get reflected. There are many document management solutions that are available for parallel working.

Just in case you get a document reviewed by your boss (and without track changes) and you want to know what he/she has done use the following

Sub CompareDoc()

Dim oDoc1 As Document
Dim oDoc2 As Document

Set oDoc1 = Documents.Open("D:\Changed Header.doc")
Set oDoc2 = Documents.Open("D:\Original Header.doc")
Application.CompareDocuments oDoc1, oDoc2, wdCompareDestinationNew, , , , , , True, True

End Sub

This compares two documents and creates a new document with Track Changes showing the changes.


There are lot of parameters to CompareDocuments method. The notable being CompareFormatting, CompareHeaders, CompareFootnotes. The last two ones are used if you want to know the changes made in Headers and Footers. Who knows you would have kept the same header from the document you cloned and your boss would have noticed and changed it. Do you want to take risk of ignoring that

See also
Comparing two Word Documents using Word VBA
Compare Files by Date

Monday, December 03, 2007

Comparing two Word Documents using Word VBA

Compare Word Documents using VBA

Here is a simple routine, which will compare two Microsoft Word documents and return the status.


Sub IsDocument_Equal()

Dim oDoc1 As Word.Document
Dim oResDoc As Word.Document

' Delete the tables from both the document

' Delete the images from both the document

' Replace Paragraphs etc

Set oDoc1 = ActiveDocument

' comparing Document 1 with New 1.doc
oDoc1.Compare Name:="C:\New 1.doc", CompareTarget:=wdCompareTargetNew, DetectFormatChanges:=True

'This will be the result document
Set oResDoc = ActiveDocument

If oResDoc.Revisions.Count <> 0 Then
'Some changes are done
MsgBox "There are Changes "
Else
MsgBox "No Changes"
End If

End Sub
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.