Tuesday, August 23, 2011

Find.Execute() in MS Word 2007 gives a "The stub received bad data" error

Here is the solution
void FindAndReplace(ref Microsoft.Office.Interop.Word.Application WordApp, object FindText, object ReplaceText)
    {
      object MatchCase = true;
      object MatchWholeWord = true;
      object MatchWildCards = false;
      object MatchSoundsLike = false;
      object nMatchAllWordForms = false;
      object Forward = true;
      object Format = false;
      object MatchKashilda = false;
      object MatchDiacritics = false;
      object MatchAlefHamza = false;
      object MatchControl = false;
      object ReadOnly = false;
      object Visible = true;
      object Replace = 2;
      object Wrap = 1;

      

      object[] Parameters = new object[] { FindText, MatchCase, MatchWholeWord, MatchWildCards
                        , MatchSoundsLike, nMatchAllWordForms, Forward, Wrap
                        , Format, ReplaceText, Replace, MatchKashilda
                        , MatchDiacritics, MatchAlefHamza,MatchControl };
      WordApp.Selection.Find.GetType().InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, WordApp.Selection.Find, Parameters);      
    }

1 comment:

  1. Are you trying to make money from your visitors via popup ads?
    In case you do, have you tried using ExoClick?

    ReplyDelete