revise 11-6
Sub detectSectionTitleOrder(ByVal control As IRibbonControl)
Call sectionTitleOrder(1)
Call sectionTitleOrder(2)
Call sectionTitleOrder(3)
End Sub
Sub sectionTitleOrder(Level As Integer)
Dim lastCall, selectNum As Integer
lastCall = 0
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False
.Replacement.Text = ""
.ParagraphFormat.OutlineLevel = Level
Do
.Execute
If Not .Found Then
Exit Do
Else
If FunctionGroup.isSectionTitle(Selection.Text) Then
selectNum = CInt(sectionNum(Selection.Text))
If selectNum > lastCall Then
If selectNum - lastCall = 1 Then
Else
Selection.Range.HighlightColorIndex = wdYellow
End If
lastCall = selectNum
Selection.Collapse wdCollapseEnd
Else
If selectNum = 1 Then
lastCall = 1
Selection.Collapse wdCollapseEnd
Else
Selection.Range.HighlightColorIndex = wdYellow
End If
Selection.Collapse wdCollapseEnd
End If
End If
End If
Loop
End With
End Sub
Function sectionNum(str As String) As String
Dim reg As New RegExp
Dim matches
With reg
.Global = 1
.Pattern = "\d(?=\. )"
Set matches = .Execute(str)
End With
sectionNum = matches(0)
End Function