I'm building a macro that loops through each word of a document and checks via a regex whether it matches a pattern and if so, writes the found word to an excel sheet. It goes like this:
For Each sentence In ActiveDocument.StoryRanges
For Each w In sentence.Words
myWord = w
If TestRegExp(myPattern, myWord) Then
WKS.Cells(myCount, 1).Value = myWord
myCount = myCount + 1
End If
Next
Next
This part works fine. Now I would also like to get the section per found word (aka "in what section did the found word appear"). I found the command "selection.Information" but no matter what I try, I only get "Section = 1". Even if I just check the whole document for sections ("ActiveDocument.Sections.Count") I only get 1. So there must be something off with the sections, but this document definitely has sections. Has anybody an idea what I do wrong?