Come mettere il mio codice nel loop?
Domanda
Voglio controllare questa condizione per l'intera pagina 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
. Soluzione
Non hai bisogno di un ciclo di fare mentre loop.È questo ciò che stai provando?
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
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow