DixiePiper
New Member
- Joined
- Oct 19, 2015
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
I have a userform that sends a copy of the workbook via email. The primary goal is to send the form back to me (or my counterpart) but it could be useful to send within the company as well. I want to ensure that any email addresses entered have a company domain. I'm not worried about actually validating the address; I just want to limit it to our company domain. I have a simpl InStr validation but if the user enters multiple email addresses and at least one is within the company, the error will not trigger.
How can I validate that all text between "@" and ".com" is one of two company domain names? Using Excel 2013 in Windows 10 OS; validation executes when the "Preview Email" or "Send Email" button is clicked.
The current code looks like this:
Right now, I'm just searching the "TO" and "CC" boxes for the company name. I'd like to refine that so it looks for "Company" or "CompanyAlt" (we have two valid domain names) between "@" and "." for every instance of "user@domain.com"
TIA!
p.s. I know this will not completely prevent the file from being improperly distributed. I just want safeguards in my process so it has to be a deliberate action of the user and not an omission on my part.
How can I validate that all text between "@" and ".com" is one of two company domain names? Using Excel 2013 in Windows 10 OS; validation executes when the "Preview Email" or "Send Email" button is clicked.
The current code looks like this:
Code:
If InStr(1, Me.cboTo.value, "Company", vbTextCompare) = 0 Or _
InStr(1, Me.txtCC.value, "Company", vbTextCompare) = 0 Then
MsgBox "Only Company recipients are allowed. Please review inputs.", vbCritical + vbOKOnly
Exit Sub
End If
Right now, I'm just searching the "TO" and "CC" boxes for the company name. I'd like to refine that so it looks for "Company" or "CompanyAlt" (we have two valid domain names) between "@" and "." for every instance of "user@domain.com"
TIA!
p.s. I know this will not completely prevent the file from being improperly distributed. I just want safeguards in my process so it has to be a deliberate action of the user and not an omission on my part.