vbscript 检测邮箱的个数是否正确

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 检测邮箱的个数是否正确相关的知识,希望对你有一定的参考价值。

Sub detectEmailCount()
Selection.HomeKey wdStory
With Selection.Find
    .ClearFormatting
    .Text = "Received: "
    .MatchWildcards = True
    .Replacement.Text = ""
    .Execute
End With
Dim myrange As Range
Set myrange = ActiveDocument.Range(ActiveDocument.Paragraphs(3).Range.End, Selection.Range.Start)
myrange.Select
If FunctionGroup.emailCount(myrange.Text) <> FunctionGroup.authorCount(ActiveDocument.Paragraphs(3).Range.Text) Then
    myrange.comments.Add myrange, "The number of authors does not match the number of email"
End If
End Sub

Function authorCount(str As String) As Integer
    If InStr(str, ", ") = 0 And InStr(str, " and ") = 0 Then
        authorCount = 1
    End If
    
    If InStr(str, ", ") = 0 And InStr(str, " and ") > 0 Then
        authorCount = 2
    End If
    
    If InStr(str, ", ") > 0 Then
        If InStr(str, " and ") = 0 Then
            ActiveDocument.Paragraphs(3).Range.HighlightColorIndex = wdRed
            ActiveDocument.Paragraphs(3).Range.comments.Add ActiveDocument.Paragraphs(3).Range, ""
        Else
            Dim reg As New RegExp
            Dim matches
            With reg
                .Global = True
                .Pattern = "\, "
                Set matches = reg.Execute(str)
                authorCount = matches.count + 2
            End With
        End If

    End If
End Function


Function emailCount(str As String) As Integer
Dim matches
Dim atCount, orCount   As Integer
Dim reg As New RegExp
With reg
    .Global = 1
    .Pattern = "\@"
    Set matches = .Execute(str)
End With
atCount = matches.count

With reg
    .Global = True
    .Pattern = " or [^ ]+\@"
    Set matches = .Execute(str)
End With

orCount = matches.count
emailCount = atCount - orCount
End Function

以上是关于vbscript 检测邮箱的个数是否正确的主要内容,如果未能解决你的问题,请参考以下文章

vbscript 检测QQ邮箱和雅虎中国邮箱

vbscript 检测文件名的期刊是否和文件里页眉页脚的期刊一致,提示询问期刊标识是否正确

vbscript 8.检测方程是否按顺序编号,是否重复编号

vbscript 检测数字和单位之间是否有空格;单位是否缩写

vbscript 检测是否有子表

vbscript 检测结论是否掉小号