-How can i create VB.net code for Wrong spell word suggestion ?
-The code should give suggestion for misspelled word from word doc.
-The Word Doc as follows,
-Input-1.docx (13.5 KB)
Imports Microsoft.Office.Interop
Module SpellChecker
Sub Main()
' The text to be spell-checked
Dim textToCheck As String = "Ths is a sampel text with a few speling erors."
' Start Word application
Dim wordApp As New Word.Application
' Minimize Word Application window (optional)
wordApp.WindowState = Word.WdWindowState.wdWindowStateMinimize
Dim doc As Word.Document = wordApp.Documents.Add()
' Disable built-in dialog boxes to keep the process silent
wordApp.ShowWindowsInTaskbar = False
wordApp.Options.CheckSpellingAsYouType = False
wordApp.Options.CheckGrammarAsYouType = False
' Insert the text into the document
doc.Content.Text = textToCheck
' Perform spell check on the inserted text
Dim proofingErrors = doc.Content.SpellingErrors
Dim errorCount As Integer = proofingErrors.Count
Console.WriteLine($"Found {errorCount} spelling error(s).")
' Iterate through errors and suggest corrections
For i As Integer = 1 To errorCount
Dim range As Word.Range = proofingErrors(i)
Console.WriteLine($"Error: {range.Text}")
For Each suggestion As String In range.GetSpellingSuggestions()
Console.WriteLine($"Suggestion: {suggestion}")
Next
Next
' Cleanup: Close the document and quit Word Application
doc.Close(False)
wordApp.Quit()
' Release COM objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(doc)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp)
doc = Nothing
wordApp = Nothing
Console.WriteLine("Spell check complete.")
End Sub
End Module
1 Like
-I have created the vb.net code but it is not working .
-Can I send here @rmorgan
-Plz go through my code and correct me .
-Invoke Code.txt (1.5 KB)