Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA Test if email address is valid

Hi

I use the following code to send a Word doc as the body of an email.
When there is an invalid email address I get the message below
I want to stop this prompt and rather do something else
Can I use code to test if the email address is valid

Sub SendDocAsMsg()
    Dim wd As Word.Application
    Dim doc As Word.Document
    Dim itm As Outlook.MailItem
    Dim ID As String
    Dim blnWeOpenedWord As Boolean
   
    Set wd = CreateObject("Word.Application")
   
    wd.Visible = True
   
    Set doc = wd.Documents.Open(Filename:="C:\Users\this\toEmail.doc", ReadOnly:=True)
    Set itm = doc.MailEnvelope.Item
    With itm
        .To = "this@email.com"
        .Subject = "My Subject"
        .Send
    End With
   
    doc.Close
    wd.Quit
 
    Set doc = Nothing
    Set itm = Nothing
    Set wd = Nothing
   
End Sub

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Interesting link, I'll be checking it out later. Thanks
Avatar of Murray Brown

ASKER

Thank you both