当电子邮件格式错误时,将单元格着色为红色

时间:2018-03-01 16:03:37

标签: vba excel-vba excel

当我的电子邮件格式错误,如screeshot http://prntscr.com/ilgbcd时,我的单元格如何变成红色?

    Function EmailValide(ByVal strEmail As String) As Boolean
    Dim re As VBScript_RegExp_55.RegExp

    ' We create a regular expression
    Set re = New VBScript_RegExp_55.RegExp

    ' We define the criteria to respect for an e-mail
    re.Pattern = "w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*"

    'The RegExp.Test function returns True if the email meets the criteria

      EmailValide = re.Test(strEmail)

    End Function

1 个答案:

答案 0 :(得分:0)

我猜您调用EmailValide()的代码会是:

Dim myCell As Range
...
Set myCell = Range("...") ' set myCell in some way
...

然后你可以使用:

If EmailValide(myCell.value) Then myCell.Interior.ColorIndex = 3