Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VBA - "End if without Block If Error"
#1
Hi,

So I am in the middle of writing a fairly simply VBA program, but I keep getting an error that I cant get rid of.

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)
  Selection.MoveEndUntil Cset:=" ", Count:=10
  TestingWord = NoPunct(Selection)
  InQuotes = QuoteState(TestingWord, InQuotes)
  If InQuotes = False Then
  For WordCount = 0 To UBound(UnusableWords)
  If TestingWord = UnusableWords(WordCount) Then
  Selection.Range.HighlightColorIndex = wdYellow
  WrongWordCount = WrongWordCount + 1
  End If
  End If
  Next WordCount
  FirstWord = False
  Loop
MsgBox ("The Program has finished and found " & WrongWordCount & " unusable words.")

Returns a "Compile Error: End If without Block If" (It highlights the 2nd "End If" when the error comes up)

this started happening after I added the quote checker. When i comment out those two lines:

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)
  Selection.MoveEndUntil Cset:=" ", Count:=10
  TestingWord = NoPunct(Selection)
  InQuotes = QuoteState(TestingWord, InQuotes)
' If InQuotes = False Then
  For WordCount = 0 To UBound(UnusableWords)
  If TestingWord = UnusableWords(WordCount) Then
  Selection.Range.HighlightColorIndex = wdYellow
  WrongWordCount = WrongWordCount + 1
' End If
  End If
  Next WordCount
  FirstWord = False
  Loop
MsgBox ("The Program has finished and found " & WrongWordCount & " unusable words.")
It Works fine.

Basically, my program is supposed to check an essay to make sure no 1st person/2nd person/conjunctions exist. if they do, highlight them. However, if a word is in quotes, dont check it. When i try "boxing" the middle of the program, it wont run. As soon as I take it out, it's fine. I get the feeling its some kind of stupid newb mistake.

Any help is appreciated,
Dan
Reply


Messages In This Thread
VBA - "End if without Block If Error" - by Yugidude - 2013-04-16, 04:46 PM
VBA - "End if without Block If Error" - by Locked - 2013-04-16, 05:00 PM
VBA - "End if without Block If Error" - by FenixR - 2013-04-16, 05:04 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)