2013-04-16, 05:12 PM
SaptaZapta Wrote:The count of IFs and END IFs is correct, but their nesting inside the inner loop is wrong.
Indentation doesn't matter to the compiler, but it makes it a lot easier for humans to see what's going on. I have added the indented code to my post above. You can easily see that you're opening the IF before the FOR loop, but closing it before the NEXT. Not allowed to do that.
Ah. That makes sence. Thanks so much for your help.
FenixR Wrote:Code:Sub CheckWords()
Selection.HomeKey Unit:=wdStory
Dim FirstRound, InQuotes As Boolean
Dim WrongWordCount As Integer
Dim WordCount As Integer
Dim TestingWord As String
WrongWordCount = 0
UnusableWords = Array("i", "me", "you", "us", "we", "my", "mine", "our", "your", "can't", "won't", "should'nt", "you're")
FirstWord = True
InQuotes = False
Do Until Selection.Bookmarks.Exists("\EndOfDoc") = True
If (FirstWord = False) Then Selection.MoveRight (2) [IF #3]
Selection.MoveEndUntil Cset:=" ", Count:=10
TestingWord = NoPunct(Selection)
InQuotes = QuoteState(TestingWord, InQuotes)
If InQuotes = False Then [IF #1]
For WordCount = 0 To UBound(UnusableWords)
If TestingWord = UnusableWords(WordCount) Then [IF #2]
Selection.Range.HighlightColorIndex = wdYellow
WrongWordCount = WrongWordCount + 1
End If [END IF #1]
End If [END IF #2]
Next WordCount
FirstWord = False
Loop
MsgBox ("The Program has finished and found " & WrongWordCount & " unusable words.")
Also you should really add an indentation level after every decision statement (If, For, etc) and reduce it after that Decision is done with.
Will Do. I learned my lesson this time...

