Results 1 to 3 of 3

Thread: Spell Check with Word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    Bangalore,karnatak
    Posts
    10

    Post

    Hi,

    I am using word.basic object to do spell check with my VB application.

    I have written code to do the spell check in the Validate event. If i use the mouse to move to another control then the validate event fires twice. In case of the usage of the tab (keyboard) then this does'nt occur.


    Private Sub txtTentArrsComm_Validate(Cancel As Boolean)

    Const strPROCEDURE_NAME = "txtTentArrsComm_Validate"

    Dim strCorrectText As String ' Holds the corrected return text

    'On Error GoTo txtTentArrsComm_ValidateError

    If ActiveControl.Name <> txtTentArrsComm.Name Then

    Exit Sub

    End If

    If mblnSpellCheck(txtTentArrsComm.Text, strCorrectText) = False Then

    Exit Sub

    End If

    txtTentArrsComm.Text = strCorrectText

    End Sub






    Public Function mblnSpellCheck(ByVal vstrIncorrectText As String, _
    ByRef rstrCorrectText As String) As Boolean

    'Created By : Sri Prabu V.C
    'Date Created : 02 Mar 2000
    '-------------------------------------------------------------------------------------------
    'Checks the spell for the Text
    '
    'Input:
    ' vstrIncorrectText - Text which has Incorrect spell
    '
    'Output:
    ' rstrCorrectText - Text which has Correct spell
    '
    'Function returns true on success
    '-------------------------------------------------------------------------------------------

    Const strPROCEDURE_NAME = "mblnSpellCheck"

    Dim objWord As Object 'Instance of the objWord Object
    Dim strRetText As String 'Holds the selected Text in objWord
    Dim strTextLines As String 'Holds the corrected text
    Dim strNote As String 'Holds etc Error Info
    Static blnCheckInstance As Boolean 'True if it is already running

    On Error GoTo mblnSpellCheckError

    If mstrFormMode = mstrREAD_MODE Then

    rstrCorrectText = vstrIncorrectText
    mblnSpellCheck = True
    Exit Function

    End If

    If blnCheckInstance = True Then

    rstrCorrectText = vstrIncorrectText
    mblnSpellCheck = True
    Exit Function

    End If

    blnCheckInstance = True

    strNote = "Create an instance of the objWord object..."

    'Create an instance of the objWord object
    Set objWord = CreateObject("Word.Basic")

    Call gSetStatus("Executing Spell Check Tool from Word...")

    strNote = "Execute the Spell Check Tool..."

    App.OleRequestPendingMsgTitle = "Spell Check Tool from Word"
    App.OleRequestPendingMsgText = "Spell Check window is behind your Application"
    App.OleRequestPendingMsgText = App.OleRequestPendingMsgText & vbNewLine & "Please finish spell checking first"

    App.OleRequestPendingTimeout = 86400000 'Set the Ole request timer to one day

    With objWord

    .AppMinimize 'Minimise the objWord object
    .AppHide 'Hide the objWord object

    .FileNew 'Open a new file document
    .Insert vstrIncorrectText 'Insert the Incorrect Text that is passed
    'in the parameter

    'Skip if any error occurs on the Spell check Tool
    On Error Resume Next

    .ToolsSpelling 'Run the tool to check the spelling

    'Reset the Error Handler to this function Error handler
    On Error GoTo mblnSpellCheckError

    .EditSelectAll 'Select the all text in the document

    strRetText = .Selection$() 'return the selected text

    strTextLines = Left$(strRetText, Len(strRetText) - 1)

    .FileClose 2 'Close the File document
    .AppClose 'Close the Application

    End With

    'Reset to Default Value
    App.OleRequestPendingTimeout = 5000
    App.OleRequestPendingMsgTitle = App.Title
    App.OleRequestPendingMsgText = vbNullString

    strNote = "Reset the Word Object..."

    'Reset the Word Object
    Set objWord = Nothing

    strNote = "Replace the return key with new line key..."

    'Replace the return key with new line key
    rstrCorrectText = Replace(strTextLines, Chr(13), vbNewLine)

    Call gSetStatus(vbNullString)

    DoEvents
    blnCheckInstance = False
    mblnSpellCheck = True
    Exit Function

    mblnSpellCheckError:

    Call gusrErr.ShowErrInfo(mstrMODULE_NAME, strPROCEDURE_NAME, strNote)
    Call gSetStatus(vbNullString)
    Me.MousePointer = vbNormal
    blnCheckInstance = False

    End Function





  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089

    Post

    Donno exactly but check http://www.vb-world.net/tips/tip81.html

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I had to comment a few lines of code because your code sample is not complete, but once I did that I could use the mouse to move to a second textbox and the validate event only fired once, so I guess you problem involves one of the calls I commented. Here is you code as I modified it.
    Code:
    Option Explicit
    
    Private Sub txtTentArrsComm_Validate(Cancel As Boolean)
    
    Const strPROCEDURE_NAME = "txtTentArrsComm_Validate"
    
    Dim strCorrectText As String ' Holds the corrected return text
    
    'On Error GoTo txtTentArrsComm_ValidateError
    
    If ActiveControl.Name <> txtTentArrsComm.Name Then
    
    Exit Sub
    
    End If
    
    If mblnSpellCheck(txtTentArrsComm.Text, strCorrectText) = False Then
    
    Exit Sub
    
    End If
    
    txtTentArrsComm.Text = strCorrectText
    
    End Sub
    
    Public Function mblnSpellCheck(ByVal vstrIncorrectText As String, _
    ByRef rstrCorrectText As String) As Boolean
    
    'Created By : Sri Prabu V.C
    'Date Created : 02 Mar 2000
    '-------------------------------------------------------------------------------------------
    'Checks the spell for the Text
    '
    'Input:
    ' vstrIncorrectText - Text which has Incorrect spell
    '
    'Output:
    ' rstrCorrectText - Text which has Correct spell
    '
    'Function returns true on success
    '-------------------------------------------------------------------------------------------
    
    Const strPROCEDURE_NAME = "mblnSpellCheck"
    
    Dim objWord As Object 'Instance of the objWord Object
    Dim strRetText As String 'Holds the selected Text in objWord
    Dim strTextLines As String 'Holds the corrected text
    Dim strNote As String 'Holds etc Error Info
    Static blnCheckInstance As Boolean 'True if it is already running
    
    On Error GoTo mblnSpellCheckError
    
    'If mstrFormMode = mstrREAD_MODE Then
    '
    'rstrCorrectText = vstrIncorrectText
    'mblnSpellCheck = True
    'Exit Function
    '
    'End If
    
    If blnCheckInstance = True Then
    
    rstrCorrectText = vstrIncorrectText
    mblnSpellCheck = True
    Exit Function
    
    End If
    
    blnCheckInstance = True
    
    strNote = "Create an instance of the objWord object..."
    
    'Create an instance of the objWord object
    Set objWord = CreateObject("Word.Basic")
    
    'Call gSetStatus("Executing Spell Check Tool from Word...")
    
    strNote = "Execute the Spell Check Tool..."
    
    App.OleRequestPendingMsgTitle = "Spell Check Tool from Word"
    App.OleRequestPendingMsgText = "Spell Check window is behind your Application"
    App.OleRequestPendingMsgText = App.OleRequestPendingMsgText & vbNewLine & "Please finish spell checking first"
    
    App.OleRequestPendingTimeout = 86400000 'Set the Ole request timer to one day
    
    With objWord
    
    .AppMinimize 'Minimise the objWord object
    .AppHide 'Hide the objWord object
    
    .FileNew 'Open a new file document
    .Insert vstrIncorrectText 'Insert the Incorrect Text that is passed
    'in the parameter
    
    'Skip if any error occurs on the Spell check Tool
    On Error Resume Next
    
    .ToolsSpelling 'Run the tool to check the spelling
    
    'Reset the Error Handler to this function Error handler
    On Error GoTo mblnSpellCheckError
    
    .EditSelectAll 'Select the all text in the document
    
    strRetText = .Selection$() 'return the selected text
    
    strTextLines = Left$(strRetText, Len(strRetText) - 1)
    
    .FileClose 2 'Close the File document
    .AppClose 'Close the Application
    
    End With
    
    'Reset to Default Value
    App.OleRequestPendingTimeout = 5000
    App.OleRequestPendingMsgTitle = App.Title
    App.OleRequestPendingMsgText = vbNullString
    
    strNote = "Reset the Word Object..."
    
    'Reset the Word Object
    Set objWord = Nothing
    
    strNote = "Replace the return key with new line key..."
    
    'Replace the return key with new line key
    rstrCorrectText = Replace(strTextLines, Chr(13), vbNewLine)
    
    'Call gSetStatus(vbNullString)
    
    DoEvents
    blnCheckInstance = False
    mblnSpellCheck = True
    Exit Function
    
    mblnSpellCheckError:
    
    'Call gusrErr.ShowErrInfo(mstrMODULE_NAME, strPROCEDURE_NAME, strNote)
    'Call gSetStatus(vbNullString)
    Me.MousePointer = vbNormal
    blnCheckInstance = False
    
    End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width