Hi All,

I have to compare the text of two word documents using VBA. These word documents contain images and tables also. But I just wanted to compare the text.

Can anybody please let me know how to do this



Re: Comparing two word documents


Try to use the property .Content of the object Document or .text of the Selection or the Range, but...

Maybe if

Code Snippet

a = Documents("MyDoc1").Content
a = Replace(a, Chr(13), "") 'remove the symbols of the paragraphs
a = Replace(a, Chr(1), "") 'remove the symbols of the pictures

b = Documents("MyDoc2").Content


If a = b then msgbox ":)"

Re: Comparing two word documents

Dilip Shrivastava

Hi ,

I want ot compare two .docx file(completely not only content text ) which returns boolean result.

Can anybody help me hoe to do this using C#



Re: Comparing two word documents


You can probably build on this :

Code Block

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 "
MsgBox "No Changes"
End If

End Sub

Re: Comparing two word documents



I would like to compare two word document and i wanted to replicate that difference in one document.

i would like to read charecter by charecter and compare those documetns, difference should be replicate into one document.

I would like to edit the word document through the VB is it possible, please le t me know.

Thanks &Regards