根据答案颜色提取答案

Sub 根据红色整理选择题答案()
    N = 0
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorRed
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        Do While .Execute
        N = N + 1
        s = s & "   " & N & "、" & RegGet(.Parent.Text, "(\w)")
        Loop
    End With
    Debug.Print s
End Sub
Public Function RegGet(ByVal OrgText As String, ByVal Pattern As String) As String
    Dim Regex As Object
    Dim Mh As Object
    Set Regex = CreateObject("VBScript.RegExp")
    With Regex
        .Global = True
        .Pattern = Pattern
    End With
    If Regex.test(OrgText) Then
        Set Mh = Regex.Execute(OrgText)
        RegGet = Mh.Item(0).submatches(0)
    Else
        RegGet = ""
    End If
    Set Regex = Nothing
End Function

  

posted @ 2019-06-11 15:14  wangway  阅读(284)  评论(0编辑  收藏  举报