private void spellCheck(TextBox txt, Label lbl) { //Spell check if (txt.Text.Length > 0) { //Create an instance of MS Word application Word.Application app = new Word.Application(); app.Visible = false; //Setup spell checker with text to check and count errors //Setting these variables is comparable to passing null to the function //This is necessary because the C# null cannot be passed by reference object temp = Missing.Value, newTemp = Missing.Value, docType = Missing.Value, vis = true; Word.Document doc = app.Documents.Add(ref temp, ref newTemp, ref docType, ref vis); doc.Words.First.InsertBefore(txt.Text); int errCount = doc.SpellingErrors.Count; //Run the checker object opt = Missing.Value; doc.CheckSpelling(ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, ref opt); //Update original text object first = 0, last = doc.Characters.Count - 1; txt.Text = doc.Range(ref first, ref last).Text; txt.Text = txt.Text.Replace("\r", "\r\n"); lbl.Text = "Spelling OK. " + errCount + " error(s) corrected "; //Close MS Word application object save = false, format = Missing.Value, rtDoc = Missing.Value; app.Quit(ref save, ref format, ref rtDoc); } }