D
D King
I need to know how to programmatically change the dictionary language for
spellcheck. I have the following code in my .net app which works great but
only checks spelling in the current word dictionary, I need to be able to
change this....any help is appreciated. Thanks.
Namespace SpellChecker
Public Class Spelling
Public Shared Function Check(ByVal TextToCheck As String) As String
TextToCheck = Trim(TextToCheck)
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 TextToCheck = "" Then
Exit Function
End If
objWord = New Word.Application
objTempDoc = objWord.Documents.Add
objWord.Visible = False
' Position Word off the screen...this keeps Word invisible
objWord.WindowState = 0
objWord.Top = -3000
' Copy the contents of the textbox to the clipboard
Clipboard.SetDataObject(TextToCheck)
' With the temporary document perform spell check
With objTempDoc
..Content.Paste()
..Activate()
..CheckSpelling()
' .CheckGrammar()
' 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
'Return the text..
Check = CType(iData.GetData(DataFormats.Text), _
String)
End If
..Saved = True
..Close()
End With
objWord.Visible = False
objWord.Quit()
MessageBox.Show("The spelling check is complete.", _
"Spell Checker", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
' Microsoft Word must be installed.
Catch COMExcep As COMException
MessageBox.Show( _
"Microsoft Word must be installed for Spell/Grammar Check " _
& "to run.", "Spell Checker")
Catch Excep As Exception
MessageBox.Show("An error has occured.", "Spell Checker")
End Try
End Function
End Class
End Namespace
spellcheck. I have the following code in my .net app which works great but
only checks spelling in the current word dictionary, I need to be able to
change this....any help is appreciated. Thanks.
Namespace SpellChecker
Public Class Spelling
Public Shared Function Check(ByVal TextToCheck As String) As String
TextToCheck = Trim(TextToCheck)
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 TextToCheck = "" Then
Exit Function
End If
objWord = New Word.Application
objTempDoc = objWord.Documents.Add
objWord.Visible = False
' Position Word off the screen...this keeps Word invisible
objWord.WindowState = 0
objWord.Top = -3000
' Copy the contents of the textbox to the clipboard
Clipboard.SetDataObject(TextToCheck)
' With the temporary document perform spell check
With objTempDoc
..Content.Paste()
..Activate()
..CheckSpelling()
' .CheckGrammar()
' 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
'Return the text..
Check = CType(iData.GetData(DataFormats.Text), _
String)
End If
..Saved = True
..Close()
End With
objWord.Visible = False
objWord.Quit()
MessageBox.Show("The spelling check is complete.", _
"Spell Checker", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
' Microsoft Word must be installed.
Catch COMExcep As COMException
MessageBox.Show( _
"Microsoft Word must be installed for Spell/Grammar Check " _
& "to run.", "Spell Checker")
Catch Excep As Exception
MessageBox.Show("An error has occured.", "Spell Checker")
End Try
End Function
End Class
End Namespace