none
How to retrieve the Corrected errors after a CheckSpelling RRS feed

  • Question

  • Hello,

    We made a code that put some text on a Document and then we want to retireve the spelling corrected words after call of CheckSpelling, but this text isnt what we want to show on the interface as we have it in a HTML editor with a specific format and want to keep it, then we would like to retrieve the corrected words afterward and replace on our HTML editor.

    To do that we stored the errros before calling CheckSpelling and cross referenced each object in microsoft.office.tools.word.document.spellingerrors the worng spelled error, after we call the CheckSpelling this reference is updated with the corrected work. For most of the cases it work without any problem, but when the spell error is two words written without a space between then (ie if it is Iappologize is corrected to "I appologize" there is oly the "I" word on this reference) what is retrieved on the object is just the first work on it.

    Set objWdDoc = m_objWdApp.Documents.Add

            ' save the not check text
            sNotChecked = strText

            ' assign text to the word application
            m_objWdApp.selection.Text = strText

            ' assign language to spell check for
            objWdDoc.Range.LanguageID = lngLangID

            If m_bIsHTML Then
                ' save spelling error objects + misspellings in the collection
                For Each objWordError In objWdDoc.SpellingErrors

                    Set objSpellingError = New cSpellingError

                    Set objSpellingError.Error = objWordError
                    objSpellingError.OldText = objWordError.Text ' Old text

                    colSpellingErrors.Add objSpellingError
                Next

                If colSpellingErrors.Count > 0 Then
                    objWdDoc.CheckSpelling
                End If
                lReturn = -1
         
            End If

    Then after that we do the following code to replace the corrected words with the wrong spelled words:

    Dim objSpellingError As cSpellingError
        Dim objWordError As Object
        Dim objTxtRange As MSHTML.IHTMLTxtRange

        Call m_objSysDocument.execCommand(ST_FORMAT_SELECTALL)
        
        If Not m_objSysDocument.selection Is Nothing Then
            If UCase(m_objSysDocument.selection.Type) <> ST_SELECTION_TYPE_CONTROL Then

                Set objTxtRange = m_objSysDocument.selection.createRange
                
                For Each objSpellingError In vcolSpellingErrors
                    objTxtRange.FindText objSpellingError.OldText, 1000000000, 6
                    If objTxtRange.Text <> "" Then
                        objTxtRange.Text = Trim(objSpellingError.Error.Words.Item(1).Text)
                    End If
                Next
             
             End If
        End If
    • Moved by Hila Shemer Thursday, July 26, 2012 8:33 PM This question is related to general Office development (From:Developing Apps for Office)
    Thursday, July 26, 2012 3:57 PM

Answers

  • But before you take the time to try that....try changing

    objTxtRange.Text = Trim(objSpellingError.Error.Words.Item(1).Text)

    to

    objTxtRange.Text = Trim(objSpellingError.Error.Text)

    Sunday, July 29, 2012 4:10 PM

All replies

  • Hi Daniel - the new apps for Office platform doesn't give you the same api/objects as our older VBA and VSTO api set, and in this release you don't have direct access to a SpellingError collection. I'm going to ask a  Moderator to move your question over to the appropriate VBA/VSTO forum.

    If you decide to attempt this using the new Office JavaScript Object Model then the sequence would look like:

    0/ Insert your Word task pane app into the active document

    1/ In the app write your text into the active document (SetSelectedDataAysnc to insert it at the cursor - see http://msdn.microsoft.com/en-us/library/office/apps/fp142145(v=office.15))

    2/ Read it back from the document into your app as Office OpenXML (GetSelectedDataAysnc and coerce as "ooxml" - see http://msdn.microsoft.com/en-us/library/office/apps/fp142294(v=office.15))

    3/ Parse the results looking for errors, example below (JavaScript has lots of cool DOM selector functions so this should be pretty easy):

    <w:proofErr w:type="spellStart"/><w:r><w:t>speeling</w:t></w:r><w:proofErr w:type="spellEnd"/>

    4/ Handle the errors in your UX..

    Hope this helps...pc

    Thursday, July 26, 2012 7:29 PM
  • But before you take the time to try that....try changing

    objTxtRange.Text = Trim(objSpellingError.Error.Words.Item(1).Text)

    to

    objTxtRange.Text = Trim(objSpellingError.Error.Text)

    Sunday, July 29, 2012 4:10 PM
  • I tried your suggestion to use the objTxtRange.Text = Trim(objSpellingError.Error.Text), but this Text field is empty. Any other suggestion to make this work?
    Tuesday, September 25, 2012 3:36 PM