Share via

Find common words between two documents

Anonymous
2016-06-23T15:55:07+00:00

I have two documents. One is a book manuscript. The other is a list of words that appear in that manuscript. However, I want to make sure that the words in this list of words are spelled the same as they are in the manuscript (there are some foreign words, proper names, etc.). My current method is to select one word from among the list of words, copy, then switch windows and search for it in the book manuscript. This can be a long process. However, is there is a way to automate this task? I was thinking some version of compare docs, but compare docs doesn't quite get at what I'm after. Any ideas?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2016-06-24T03:20:56+00:00

See: http://www.mrexcel.com/forum/general-excel-discussion-other-questions/947455-msword-delete-duplicate-words-selected-text-2.html#post4556268

If you run the macro there on a copy of your manuscript, it will produce an alpha-sorted list of all the words used in the document. As coded, it omits words of three characters or less and words from a pre-defined exclusions list. You could, for example, add all the words in your list of words to the pre-defined exclusions list, so that only words not included in it are output.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2016-06-24T02:45:33+00:00

If you run a macro containing the following code when the book manuscript is the active document, it will ask you to open the document containing the list of words and then create a new document that will contain a list of any of the words that are not in the manuscript.

Dim source As Document, Target As Document, DocList As Document

Dim FD As Dialog

Dim i As Long

Set source = ActiveDocument

Set FD = Application.FileDialog(msoFileDialogFilePicker)

With FD

    .Title = "Select the file containing the list of words."

    .Filters.Clear

    .Filters.Add "Word Documents", "*.doc; *.docx"

    .AllowMultiSelect = False

    If .Show = -1 Then

        Set DocList = Documents.Open(.SelectedItems(1))

    Else

        MsgBox "You did not select the document containing the words."

        Exit Sub

    End If

End With

Set Target = Documents.Add

Target.Range.InsertAfter "The following words do not appear in the document:" & vbCr

With DocList

    For i = 1 To .Paragraphs.count

        If InStr(source.Range.Text, .Paragraphs(i).Range.Words(1).Text) = 0 Then

            Target.Range.InsertAfter .Paragraphs(i).Range.Words(1).Text & vbCr

        End If

    Next i

End With

Was this answer helpful?

0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2016-07-01T01:10:33+00:00

    Hi Eric,

    There is no problem with that line of code here.

    You are using Office 2010 on Windows and not a Mac?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-06-30T12:46:13+00:00

    Doug, could you please give me some guidance on debugging this macro?

    It's flagging this line: Set FD = Application.FileDialog(msoFileDialogFilePicker)

    Thanks, Eric

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-06-28T13:18:33+00:00

    I'm getting a Debug message on that macro. When it takes me to the macro, it shows a problem with this line:

    Set FD = Application.FileDialog(msoFileDialogFilePicker)

    Any ideas?

    Was this answer helpful?

    0 comments No comments