VB.NET • Invoke Word's Spell Checker

Listing 1. Create an instance of a Word application, then open a new document, copy the source textbox text, and launch the spell checker. The user can correct the text and copy it back to the original application.

If txtComment.Text.Length > 0 Then
	Dim word As New Word.ApplicationClass()
	Dim doc As Word.DocumentClass = _
		word.Documents.Add()
	word.Visible = False

	Clipboard.SetDataObject(txtComment.Text)
	doc.Content.Paste()
	doc.Activate()
	doc.CheckSpelling()

	doc.Content.Copy()
	If Clipboard.GetDataObject.GetDataPresent( _
		DataFormats.Text) Then
	txtComment.Text = _
		CType(Clipboard.GetDataObject.GetData( _
		DataFormats.Text), String)
	End If

	doc.Saved = True
	doc.Close()
	word.Quit()
End If