locked
how to add (if , then) when find CheckSpelling is error to words ؟ RRS feed

  • Question

  • I want show message when find error to word in textbox use CheckSpelling ?

    my code :

    If TextBox19.Text.Length > 0 Then
                Dim wordapp As New Word.Application
                wordapp.Visible = False
                Dim doc As Word.Document = wordapp.Documents.Add()
                Dim range As Word.Range
                range = doc.Range()
                range.Text = TextBox19.Text
                doc.Activate()
                doc.CheckSpelling()
                Dim chars() As Char = {CType(vbCr, Char), CType(vbLf, Char)}
                TextBox19.Text = doc.Range().Text.Trim(chars)
                doc.Close(SaveChanges:=False)
                wordapp.Quit()
            End If

    I want :

    If doc.CheckSpelling > 0 Then
                    MessageBox.Show("find error in word")
                Else
                    MessageBox.Show("dount find error in word")
                End If

    Monday, July 24, 2017 9:00 AM

Answers

  • Hi srajmuneer,

    I use Word.ProofreadingErrors to check error count.

     If TextBox3.Text.Length > 0 Then
                Dim wordapp As New Word.Application
                wordapp.Visible = False
                Dim doc As Word.Document = wordapp.Documents.Add()
                Dim range As Word.Range
                range = doc.Range()
                range.Text = TextBox3.Text
                doc.Activate()
                Dim SpellCollection As Word.ProofreadingErrors
                SpellCollection = range.SpellingErrors
                If SpellCollection.Count > 0 Then
                    MessageBox.Show("find error!")
                Else
                    MessageBox.Show("no find error!")
                End If
    End If
    

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Sunday, July 30, 2017 6:22 PM
    Tuesday, July 25, 2017 3:08 AM

All replies

  • I want show message when find error to word in textbox use CheckSpelling ?

    What CheckSpelling are you using?  If this code is running under interop then the method returns a result you can test.
    https://msdn.microsoft.com/en-us/library/ms178794.aspx

    If it's running under VBA then the best you can do is display a dialog for each error.
    https://msdn.microsoft.com/VBA/Word-VBA/articles/document-checkspelling-method-word

    Monday, July 24, 2017 10:27 PM
  • Hi srajmuneer,

    I use Word.ProofreadingErrors to check error count.

     If TextBox3.Text.Length > 0 Then
                Dim wordapp As New Word.Application
                wordapp.Visible = False
                Dim doc As Word.Document = wordapp.Documents.Add()
                Dim range As Word.Range
                range = doc.Range()
                range.Text = TextBox3.Text
                doc.Activate()
                Dim SpellCollection As Word.ProofreadingErrors
                SpellCollection = range.SpellingErrors
                If SpellCollection.Count > 0 Then
                    MessageBox.Show("find error!")
                Else
                    MessageBox.Show("no find error!")
                End If
    End If
    

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Sunday, July 30, 2017 6:22 PM
    Tuesday, July 25, 2017 3:08 AM
  • What CheckSpelling are you using?

     thanks Acamar I'm use CheckSpelling  in Microsoft word
    Friday, July 28, 2017 8:52 PM
  • I'm use CheckSpelling  in Microsoft word

    I will take a guess that you are using interop - the code is consistent with that approach.

    According to the example at the site I referred to you would use something like:

        If doc.CheckSpelling(range.Text) = True Then
            result = "Spelled correctly."
        End If



    Friday, July 28, 2017 9:39 PM
  • thank you very much Cherry Bu
    Sunday, July 30, 2017 6:22 PM