我目前正在使用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/