word vba顺题号 括号填答案

Sub 试卷顺题号()
    Selection.HomeKey 6
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    n = 0
    With Selection.Find
            .text = "(^13)[0-9]@(.)"
            .Wrap = wdFindContinue
            .MatchWildcards = True
            Do While .Execute
                n = n + 1
                .Replacement.text = "\1" & n & "\2"
                .Execute Replace:=wdReplaceOne
                'Stop
            Loop
    End With
End Sub
'CABACBCADCABBABBBDCDABACDBBDCBCCDACAAABCBD
Sub 答案填在括号里()
    s = "CABACBCADCABBABBBDCDABACDBBDCBCCDACAAABCBD"
    Selection.HomeKey 6
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    n = 0
    With Selection.Find
            .text = "(()())"
            .Wrap = wdFindContinue
            .MatchWildcards = True
            Do While .Execute
                n = n + 1
                .Replacement.text = "\1" & Mid(s, n, 1) & "\2"
                .Execute Replace:=wdReplaceOne
                Selection.Collapse WdCollapseDirection.wdCollapseEnd
                Debug.Print n
'                Stop
            Loop
    End With
End Sub

  

posted @ 2024-10-13 22:18  wangway  阅读(5)  评论(0编辑  收藏  举报