Word.Application() not defined?
-
Hello all I'm trying to include the a Grammer check into my app; one of the approaches that I've come across is using MS.Words' but it seem that I'm facing somedefficulties that I can't figure out;
mports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form ' Invokes either the spell or grammar checker. Private Sub SpellOrGrammarCheck(ByVal blnSpellOnly As Boolean) Try ' Create Word and temporary document objects. Dim objWord As Object Dim objTempDoc As Object ' Declare an IDataObject to hold the data returned from the ' clipboard. Dim iData As IDataObject ' If there is no data to spell check, then exit sub here. If TextBox1.Text = "" Then Exit Sub End If objWord = New Word.Application() // My problem is here as it shows that it is not defined objTempDoc = objWord.Documents.Add objWord.Visible = False ' Position Word off the screen...this keeps Word invisible ' throughout. objWord.WindowState = 0 objWord.Top = -3000 ' Copy the contents of the textbox to the clipboard Clipboard.SetDataObject(TextBox1.Text) ' With the temporary document, perform either a spell check or a ' complete ' grammar check, based on user selection. With objTempDoc .Content.Paste() .Activate() If blnSpellOnly Then .CheckSpelling() Else .CheckGrammar() End If ' After user has made changes, use the clipboard to ' transfer the contents back to the text box .Content.Copy() iData = Clipboard.GetDataObject If iData.GetDataPresent(DataFormats.Text) Then TextBox1.Text = CType(iData.GetData(DataFormats.Text), _ String) End If .Saved = True .Close() End With objWord.Quit() MessageBox.Show("The spelling check is complete.", _ "Spell Checker", MessageBoxButtons.OK, _ MessageBoxIcon.Information) ' Microsoft Word must be installed. Catch COMExcep As COMException
-
Hello all I'm trying to include the a Grammer check into my app; one of the approaches that I've come across is using MS.Words' but it seem that I'm facing somedefficulties that I can't figure out;
mports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form ' Invokes either the spell or grammar checker. Private Sub SpellOrGrammarCheck(ByVal blnSpellOnly As Boolean) Try ' Create Word and temporary document objects. Dim objWord As Object Dim objTempDoc As Object ' Declare an IDataObject to hold the data returned from the ' clipboard. Dim iData As IDataObject ' If there is no data to spell check, then exit sub here. If TextBox1.Text = "" Then Exit Sub End If objWord = New Word.Application() // My problem is here as it shows that it is not defined objTempDoc = objWord.Documents.Add objWord.Visible = False ' Position Word off the screen...this keeps Word invisible ' throughout. objWord.WindowState = 0 objWord.Top = -3000 ' Copy the contents of the textbox to the clipboard Clipboard.SetDataObject(TextBox1.Text) ' With the temporary document, perform either a spell check or a ' complete ' grammar check, based on user selection. With objTempDoc .Content.Paste() .Activate() If blnSpellOnly Then .CheckSpelling() Else .CheckGrammar() End If ' After user has made changes, use the clipboard to ' transfer the contents back to the text box .Content.Copy() iData = Clipboard.GetDataObject If iData.GetDataPresent(DataFormats.Text) Then TextBox1.Text = CType(iData.GetData(DataFormats.Text), _ String) End If .Saved = True .Close() End With objWord.Quit() MessageBox.Show("The spelling check is complete.", _ "Spell Checker", MessageBoxButtons.OK, _ MessageBoxIcon.Information) ' Microsoft Word must be installed. Catch COMExcep As COMException
-
You need to specify the fully qualified name as I had mentioned before ie use
Microsoft.Office.Interop.Word.Application
.
जय हिंद