vba - Visual Basic编辑器中Excel格式的电子邮件字段中的错误处理

标签 vba error-handling excel

我目前正在使用Excel编写表单。我想知道是否有一种方法可以搜索字段中的某些字符。我正在考虑使用此方法构造代码以检查在电子邮件字段中输入的数据的完整性。它将查找“@”和“”。如果不存在,可能会输出一个 bool(boolean) 值(真或假)。

先感谢您。

最佳答案

您可以将值传递给这样的函数:

Function blnValidEmail(strText As String) As Boolean

    Dim intPosAt As Integer
    Dim intPosDot As Integer

    'finds the position of the @ symbol'
    intPosAt = InStr(strText, "@")

    'finds the position of the last full stop'
    'checks the last full stop because you might'
    'have an address like jane.doe@something.com'
    intPosDot = InStrRev(strText, ".")

    'makes sure that both exist'
    If intPosAt > 0 And intPosDot > 0 Then
        'makes sure that there is a fullstop after the @'
        If intPosDot > intPosAt Then
            blnValidEmail= True
        End If
    End If

End Function

关于vba - Visual Basic编辑器中Excel格式的电子邮件字段中的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2064471/

相关文章:

vba - Outlook VBA 将 .xls 附件转换为 .xlsx

vba - 使用 GetObject 编辑其他工作簿工作 1 次 x

arrays - VB中对象数组的使用方法

python - 除非设置了调试标志,否则隐藏回溯

c++ - 当数组超出范围时,通过异常检查是否安全?

validation - 在“调用应用程序”阶段将inputText标记为无效

javascript - 从 servlet 响应中下载 JavaScript 中的 Excel

vba - VBA工作表与多个单元格一起更改

excel - 在 Power Query 中使用文本字符串查找所有代码组合

java - 如何读取扩展名为*.xlsx的Excel文件?