Word 2013 Crash on Find.Execute RRS feed

  • Question

  • I'm using VSTO ThisAddIn and Word 2013.

    I want to replace all occurences of the one string with another using Find.Execute and mark this action with custom undo message. The code is:

    application.UndoRecord.StartCustomRecord("Some Message");
    var find = application.ActiveDocument.Content.Find;
    find.Execute("string to be replaced"
      , ReplaceWith: "second string"
      , Replace: WdReplace.wdReplaceAll);

    So I have a Word Crash during this code run. If I change Replace: WdReplace.wdReplaceAll to Replace: WdReplace.wdReplaceOne, I'll have word working, but I need to replace all occurrences.

    Any suggestions/workarounds?

    Wednesday, November 9, 2016 3:16 PM

All replies

  • Hi,

    I test the code using

            private void UndoRecord_Click(object sender, RibbonControlEventArgs e)
                Globals.ThisAddIn.Application.UndoRecord.StartCustomRecord("Some Message");
                var find = Globals.ThisAddIn.Application.ActiveDocument.Content.Find;
                find.Execute("string to be replaced"
                  , ReplaceWith: "second string"
                  , Replace: WdReplace.wdReplaceAll);

    Word would not crash in Office2013 or Office2016.

    I suggest you test the code snippet and check if it would cause the issue.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, November 10, 2016 2:15 AM