码迷,mamicode.com
首页 > 编程语言 > 详细

WordVBA提取红色字体选项

时间:2020-06-30 12:48:07      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:forms   正确答案   sub   lob   net   字体   vba   fun   regexp   

Sub 提取红色正确答案选项()
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorRed
    Selection.Find.Replacement.ClearFormatting
    n = 0
    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
            Debug.Print n & "、" & RegGet(.Parent.Range.Text, "([ABCD])")
        Loop
    End With
End Sub
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

  

WordVBA提取红色字体选项

标签:forms   正确答案   sub   lob   net   字体   vba   fun   regexp   

原文地址:https://www.cnblogs.com/nextseven/p/13212751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!