Microsoft.Office.Interop.Word's Find.MatchWholeWord is not working properly RRS feed

  • Question

  • I am writing code for replacing text within Word ML documents. For this purpose I am using the Microsoft.Office.Interop.Word (ver 11.0) DLL. The issue that I am facing is that when the Find.MatchWholeWord is set to true, it is automatically setting itself to false. Moreover, I tried setting the MatchWholeWord parameter to true in the Find.Execute() method. However, the find result is returning true even if the document text does not contain the search text as a whole word and if the search text is contained as a part of another word in the document.

    For information, I am using Microsoft Office 2003.

    Any help on this regard is greatly appreciated.

    Friday, November 22, 2013 7:05 AM


  • Hi,

    According to your description, the Find.MatchWholeWord property and the return value of the Find.Execute() method are not working properly.

    I try to reproduce your issue with the code below. I find when I type the "jan" in the document the popped message will be "Yes" and when I type in the "jane" the popped message will be "No". So I think the Find.MatchWholeWord property works well in my code.

    private void FindExecute(Word.Document wordDoc)
        object missing = Type.Missing;
        Word.Range rng = wordDoc.Sentences[1];
        object s = "jan";
        if (rng.Find.Execute(ref s, ref missing, true,
        ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing))

    Since I cannot reproduce your issue and I think the issue is related to the code or the document. If convenient, would you mind sharing the code snippet and the sample document from SkyDrive to help us to resolve your issue?

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 25, 2013 2:40 AM