How to check spelling in Excel programmatically
By Miguel Santos
This FAQ will help you to check word spelling in Excel using .NET. The CheckSpelling method works slightly different depending if the object is the Application, Wroksheet or Range object.
You can check spelling at application, worksheet or range level by using CheckSpelling
method:
Application: It checks words using Excel spelling resources
private void DoSpellingCheck(Excel.Application app, string wordToCheck)
{
app.CheckSpelling(wordToCheck, Type.Missing, Type.Missing);
}
Worksheet: It checks headers, footers, and objects existing
on a worksheet.
private void DoSpellingCheck(Excel.Worksheet sheet)
{
sheet.CheckSpelling(Type.Missing, true, true,
Office.MsoLanguageID.msoLanguageIDEnglishUS);
}
Range
or Cell:It checks spelling of a range or cell object.
private void DoSpellingCheck(Excel.Range range)
{
range.CheckSpelling(Type.Missing, true, true,
Office.MsoLanguageID.msoLanguageIDEnglishUS);
}
This method is also available in other Excel objects like named ranges, chart
and controls like textbox, group box.
The sample code is in C# but
can translated to VB.NET very easily, for example the application code in VB.NET
will look like:
Private Sub CheckSpelling(Dim app As Excel.Application, Dim wordToCheck As String)
app.CheckSpelling(wordToCheck)
End Sub
For more information check:
http://msdn.microsoft.com/en-us/library/aa223822(office.11).aspx
How to check spelling in Excel programmatically (561 Views)