I have a document with multiple sections (doesn't matter) with Heading 1 paragraphs, and I'm trying to get each Heading 1 'chunk' into a range so that I can do statistics, etc. on just that piece
Example document structure:
DocStart
text
H1 #1
text
H1 #2
text
H1 #3
text
DocEnd
So I'm trying to get a loop that returns 4 Ranges:
DocStart to just before H1 #1 (first char at top to last char before the H1 paragraph)
H1 #1 to just before H1 #2
H1 #2 to just before H1 #3
H1 #3 to DocEnd
Can someone get me started please?
Edit#2 - This is what I have so far. Seems to work, but not sure if it'll stand the test of time. Word's object model is pretty much a mystery to me, so I'm open to any suggestions
Option Explicit
Sub ChunkHeading1()
Dim rChunk As Range
Dim n As Long
Selection.HomeKey Unit:=wdStory
Set rChunk = Selection.Range
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles("Heading 1")
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
'remember end position = before the start of the Heading 1 paragraph
Selection.MoveLeft Unit:=wdCharacter, Count:=2
rChunk.End = Selection.End
n = n + 1
MsgBox "Chunk # " & n & " -- " & rChunk.ComputeStatistics(wdStatisticWords)
rChunk.Move Unit:=wdParagraph, Count:=2
rChunk.Select
Loop
'from the last Heading 1 to end of doc
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
n = n + 1
MsgBox "Chunk # " & n & " -- " & Selection.Range.ComputeStatistics(wdStatisticWords)
End With
End Sub