how to make word doc inivible when using word object to spell check in vb.net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,<br/>
<br/>
I am working on desktop app in vb.net. i am using a above code to check the spelling and grammer by using word object and its working fine but when i do cancel and close Spell check window there is word file comes up.<br/>
<br/>
Private Function SpellOrGrammarCheck(ByVal blnSpellOnly As Boolean, ByRef sWord As String)<br/>
<br/>
Try<br/>
Create Word and temporary document objects.<br/>
Dim objWord As New Word.Application<br/>
Dim objTempDoc As Object<br/>
Declare an IDataObject to hold the data returned from the clipboard.<br/>
Dim iData As IDataObject<br/>
<br/>
If there is no data to spell check, then exit sub here.<br/>
If sWord = "" Then<br/>
Exit Function<br/>
End If<br/>
objTempDoc = objWord.Documents.Add<br/>
objWord.Visible = False<br/>
<br/>
Position Word off the screen...this keeps Word invisible throughout.<br/>
objWord.WindowState = 2<br/>
<br/>
objWord.Top = -3000<br/>
<br/>
Copy the contents of the textbox to the clipboard<br/>
Clipboard.SetDataObject(sWord)<br/>
<br/>
With the temporary document, perform either a spell check or a complete<br/>
grammar check, based on user selection.<br/>
With objTempDoc<br/>
.Content.Paste()<br/>
.Activate()<br/>
If blnSpellOnly Then<br/>
.CheckSpelling()<br/>
Else<br/>
.CheckGrammar()<br/>
End If<br/>
After user has made changes, use the clipboard to<br/>
transfer the contents back to the text box<br/>
.Content.Copy()<br/>
iData = Clipboard.GetDataObject<br/>
If iData.GetDataPresent(DataFormats.Text) Then<br/>
sWord = CType(iData.GetData(DataFormats.Text), String)<br/>
End If<br/>
.Saved = True<br/>
.Close()<br/>
End With<br/>
<br/>
objWord.Quit()<br/>
objWord = Nothing<br/>
objTempDoc = Nothing<br/>
Return sWord<br/>
<br/>
MessageBox.Show("The spelling check is complete.", "Spell Checker", MessageBoxButtons.OK, MessageBoxIcon.Information)<br/>
<br/>
Microsoft Word must be installed.<br/>
Catch COMExcep As COMException<br/>
MessageBox.Show("Microsoft Word must be installed for Spell/Grammer Check to run.", "Spell Checker")<br/>
<br/>
Catch Excep As Exception<br/>
Error_Handler_File(Me.Name, Err.Erl.ToString, ex.Message, Err.Number.ToString)<br/>
End Try<br/>
<br/>
End Function<br/>
<br/>
Please help me out to hide it.

View the full article
 
Back
Top