ActiveDocument.Words(i).Characters.Last.Text statment not working
I'm working on a text mining program to detect instances of hiatus, which is when the last letter of a word and the first letter of the next word both start with vowels. Eventually I'd like to use and/or logic to detect any vowel combinations, but I was having difficulty with the program and simplified things to figure out what was wrong. My If statement is never triggering because the ActiveDocument.Words(i).Characters.Last.Text statement doesn't seem to work. I can find vowels as the first letter of the word using ActiveDocument.Words(j).Characters.First.Text with no problems, but for some reason it can't detect them at the end of words. Here is a simplified version of the code I've been using to troubleshoot. Its only trying to look for the letter "e" at the end of words, but the if statement won't trigger. Thanks in advance for the help!
Sub hiatus()
'this bit selects the document and sets up a way to cycle through words
Dim doc As Word.Document Dim i As Integer
Dim j As Integer
Dim hiatus As Integer
'initialize counters must start on 1st and 2nd word
i = 1
j = 2
hiatus = 0
Set doc = Word.ActiveDocument
'loop through words
For i = 1 To (doc.words.Count - 1)
'this bit searches for if the word meets certain criteria
If ActiveDocument.Words(i).Characters.Last.Text = "e" Then
hiatus = hiatus + 1
End If
'increment counters
j = j + 1
Next i
doc.Range.InsertAfter "hiatus =" & (CStr(hiatus))
End Sub
|