+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Spammer
    Join Date
    02-26-2009
    Location
    India
    MS-Off Ver
    Outlook
    Posts
    98

    MS words spellcheck

    Hi,

    Does anyone know how to access MS Words' spell & grammar checking function from their program?
    I am writing my own text editor and wants to be able to check for grammar/spelling mistake. Since MS Words has such a capability, i would like to utilize it.
    Is there any .dll file we could use? Where can i find it and what does the Api look like?

    many thanks,

  2. #2
    Forum Administrator
    Join Date
    03-18-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: MS words spellcheck

    This code is basically provides the spelling and grammar checking facilities of Microsoft Word in a stand-alone Windows application.Just try this.

    Code:
    Imports 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()
                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
                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 Sub
    
        Private Sub btnSpellCheck_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnSpellCheck.Click
            SpellOrGrammarCheck(True)
        End Sub
    
        Private Sub btnGrammarCheck_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnGrammarCheck.Click
            SpellOrGrammarCheck(False)
        End Sub
    
    End Class
    ExlGuru

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0