Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Compare two word document & Find no. of omitted,missing, added word


Edit [copied source code over from otherwise duplicate question - Sascha Lefèvre]:
VB.NET
Dim c As Integer = doc2.Sentences(1).Words.Count
                        Dim c1 As Integer = doc1.Sentences(1).Words.Count - 1
                        'Dim c1 As Integer = doc1.Sentences(2).Words.Count - 1
                        If c1 > c Then
                            b = 1
                            MsgBox("First")
                            For a = 1 To c - 1
                                'MsgBox(doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() & "*****" & doc2.Sentences(1).Words(a).Text.ToString() & "*****")
                                If doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() Then

                                    b = b + 1
                                    If doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() And doc1.Sentences(1).Words(b + 1).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() Then
                                        mistake = mistake + 1
                                        b = b - 1
                                    Else
                                        added = added + 1
                                        b = b + 1
                                    End If
                                Else
                                    b = b + 1
                                End If
                            Next
                            If added = 0 Then
                                added = added + 1
                            End If
                        ElseIf c1 < c Then
                            b = 1
                            MsgBox("Second")
                            For a = 1 To c - 1
                                'MsgBox(doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() & "*****" & doc2.Sentences(1).Words(a).Text.ToString() & "*****")
                                If doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b).Text.Trim(" ").ToString() Then

                                    b = b + 1
                                    If doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b).Text.Trim(" ").ToString() And doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b + 1).Text.Trim(" ").ToString() Then
                                        mistake = mistake + 1
                                        b = b - 1
                                    Else
                                        omitted = omitted + 1
                                        b = b + 1
                                    End If
                                Else
                                    b = b + 1
                                End If
                            Next
                            
                        Else
                            MsgBox("Third")

                            For a = 1 To c
                                If doc1.Sentences(1).Words(a).Text <> doc2.Sentences(2).Words(a).Text Then

                                    mistake = mistake + 1
                                End If
                            Next
                        End If

                        MsgBox("Mistake " & mistake & " Omitted " & omitted & " Added " & added)
Posted
Updated 10-Jan-16 17:56pm
v2
Comments
dan!sh 10-Jan-16 23:00pm    
This is not enough information to provide any help. Can you post details of what you are trying to do and also the code that you have already tried. Update your question with these details. Please do not post code in comments.

1 solution

I would use the built-in functionality in and let the Word to track the changes and do the comparison. To use those abilities from Word you'd need to use Interop. For an example, have a look at Walkthrough: Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic)[^]. The example is for Excel, but the idea is the same.

To toggle the track changes on and off, see _Document.TrackRevisions property (Microsoft.Office.Interop.Word)[^] and to do the comparison, see _Application.CompareDocuments method (Microsoft.Office.Interop.Word)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900