kerrypnx
11/29/2018 - 8:53 AM

Figure 某个子图

revise 11-29

Sub checkSubcitation()
Dim aimT    As String
'首先做一个拆分figure 子图的功能,2-7, 3a,d类似这种
Selection.HomeKey wdStory
With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Text = "Figure " + "[0-9]{1,}[a-zA-Z]"
    .Wrap = wdFindStop
    .Replacement.Text = ""
    Do
    .Execute
    If .Found Then
    aimT = Selection.Text
    Selection.Bookmarks.Add ("myBK")
    Selection.MoveRight wdWord, 1
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Font.Bold = True
            .Text = "Figure" + " " + FunctionGroup.getNum(aimT)
            .Replacement.Text = ""
            .Execute
            If .Found Then
                Selection.Paragraphs(1).Range.Select
                With Selection.Range.Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    .Font.Bold = True
                    .Text = getSubNum(CStr(aimT))
                    .Execute
                    If .Found Then
                        
                    Else
                        Selection.GoTo What:=wdGoToBookmark, name:="myBK"
                        Selection.Range.HighlightColorIndex = wdRed
                        Selection.comments.Add Selection.Range, "can't find this sub figure explan"
                        ActiveDocument.Bookmarks("myBK").Delete
                    End If
                End With
                           
            End If
        End With
    Else
        Exit Do
    End If
    Selection.MoveRight wdWord, 1
    Loop
End With


End Sub
Function getSubNum(str As String) As String
    Dim reg As New RegExp
    Dim matches
    With reg
        .Global = 1
        .Pattern = "\d+(\w+)"
        Set matches = .Execute(str)
    End With
  If reg.test(str) = True Then
    getSubNum = matches(0).SubMatches(0)
End If
End Function