Question

I want to check this condition for the whole page in word.

If Options.CheckGrammarWithSpelling = True Then
    Selection.Comments.Add Range:=Selection.Range
    Selection.TypeText Text:="WRONG!!!"
    'ActiveDocument.CheckGrammar
Else
    'ActiveDocument.CheckSpelling
    'Selection.Comments.Add Range:=Selection.Range
End If
Was it helpful?

Solution

You don't need a Do While Loop. Is this what you are trying?

Sub DoSpellCheckAndComment()
    Dim oWord As Range
    Dim StoryRange As Range

    For Each StoryRange In ActiveDocument.StoryRanges
        Application.CheckSpelling Word:=StoryRange
        For Each oWord In StoryRange.Words
            If Not Application.CheckSpelling(Word:=oWord.Text) Then
                oWord.Select
                oWord.Comments.Add Range:=Selection.Range, Text:="WRONG!!!"
            End If
        Next oWord
    Next StoryRange
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top