TheWennerWoman
Active Member
- Joined
- Aug 1, 2019
- Messages
- 308
- Office Version
- 365
- Platform
- Windows
Hello,
I am using the following function to parse a list of email addresses to check if they're valid (if this code was written by someone on here, many thanks, it works a treat!)
I need it amended slightly to accommodate where more than one email address exists in a cell. For example, a cell might contain
This would be a valid "address" in the .To field when using VBA to send emails.
Any pointers (or workarounds) appreciated as always.
Thank you for taking the time to read
I am using the following function to parse a list of email addresses to check if they're valid (if this code was written by someone on here, many thanks, it works a treat!)
VBA Code:
Public Function ValidateEmail(ByVal sEmail As Variant) As Boolean
On Error GoTo Error_Handler
Dim oRegEx As Object
If Not IsNull(sEmail) Then
Set oRegEx = CreateObject("vbscript.regexp")
oRegEx.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
ValidateEmail = oRegEx.Test(sEmail)
Else
ValidateEmail = True
End If
Error_Handler_Exit:
On Error Resume Next
If Not oRegEx Is Nothing Then Set oRegEx = Nothing
Exit Function
Error_Handler:
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: ValidateEmail" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function
I need it amended slightly to accommodate where more than one email address exists in a cell. For example, a cell might contain
Code:
donald.trump@us.gov; vladimir.putin@russia.ru
This would be a valid "address" in the .To field when using VBA to send emails.
Any pointers (or workarounds) appreciated as always.
Thank you for taking the time to read