H
hafabee
Hi.
I have a routine that loops through every word in the active document,
sentence by sentence. Here is the code outline:
For Each rngRange In ActiveDocument.StoryRanges
For Each rngSentence In rngRange.Sentences
For Each rngWord In rngSentence.Words
MyWordProcess(rngWord)
Next rngWord
Next rngSentence
Next rngRange
For Each shpShape In ActiveDocument.Shapes
If shpShape.TextFrame.HasText Then
rngRange = shpShape.TextFrame.TextRange
For Each rngSentence In rngRange.Sentences
For Each rngWord In rngSentence.Words
MyWordProcess(rngWord)
Next rngWord
Next rngSentence
End If
Next shpShape
End If
This code always goes through the doc from the beginning. I would like
to modify it to instated start where the cursor currently is in the
doc, but I cannot figure out how to do this given the two separate
loops. Is there a cleaner way to loop through all the words in a
document? I do not need to include the page headers/footers, but I do
need to include the text boxes. In processing each word I need to be
able to show the sentence it is in for context.
Thanks.
I have a routine that loops through every word in the active document,
sentence by sentence. Here is the code outline:
For Each rngRange In ActiveDocument.StoryRanges
For Each rngSentence In rngRange.Sentences
For Each rngWord In rngSentence.Words
MyWordProcess(rngWord)
Next rngWord
Next rngSentence
Next rngRange
For Each shpShape In ActiveDocument.Shapes
If shpShape.TextFrame.HasText Then
rngRange = shpShape.TextFrame.TextRange
For Each rngSentence In rngRange.Sentences
For Each rngWord In rngSentence.Words
MyWordProcess(rngWord)
Next rngWord
Next rngSentence
End If
Next shpShape
End If
This code always goes through the doc from the beginning. I would like
to modify it to instated start where the cursor currently is in the
doc, but I cannot figure out how to do this given the two separate
loops. Is there a cleaner way to loop through all the words in a
document? I do not need to include the page headers/footers, but I do
need to include the text boxes. In processing each word I need to be
able to show the sentence it is in for context.
Thanks.