2
votes

I know how to get every paragraph in a word document. But I am looking for a way to loop through each word in a MS Word document.

Sub Sample()

Dim apara As Paragraph
Dim lineText As String

For Each apara In ActiveDocument.Paragraphs

     lineText = apara.Range

     'Now print the paragraph 

     Debug.Print lineText 

Next apara

End Sub
2
Have you tried this?Automate This

2 Answers

6
votes
For Each sentence In ActiveDocument.StoryRanges
    For Each w In sentence.Words
        Debug.Print w
    Next
Next
0
votes

Here's another, very similar solution which may be helpful for others. The accepted answer grabs truly all words in the document including header, footer, etc., whereas this answer will only grab words in the "main" area of the document.

For Each para In ActiveDocument.Paragraphs
    For Each wrd In para.Range.Words
        Debug.Print wrd
    Next wrd
Next para