Consulting

Results 1 to 3 of 3

Thread: emailItem.Send Error Message "Outlook doesn't recognize one or more names"

  1. #1
    VBAX Regular
    Joined
    Feb 2018
    Location
    Portland
    Posts
    26
    Location

    emailItem.Send Error Message "Outlook doesn't recognize one or more names"

    Hello

    I have an Excel workbook that has a form the user fills out. When finished, the user clicks a Submit button and the underlying code attaches the workbook to an Outlook email. This button worked just fine last week. This week I am getting an error message even though I have not made any changes.

    My code is this:
    Sub Submit()
        Dim Answer As VbMsgBoxResult
        Answer = MsgBox("Are you ready to submit?", vbYesNo + vbQuestion + vbDefaultButton2, "Submission Confirmation")
            If Answer = vbYes Then
                Dim FileName1 As String
                FileName1 = Range("A2").Text
                ActiveWorkbook.SaveAs Filename:=FileName1
                Dim emailApp As Object
                Dim emailItem As Object
                Set emailApp = CreateObject("Outlook.Application")
                Set emailItem = emailApp.CreateItem(0)
                'Email Subject
                Dim SubTitle As String
                SubTitle = Range("A1").Text
                Dim selfEmail As Variant
                Set selfEmail = Range("F6")
    
                'Email Details
                emailItem.to = "JimSmith@xyz.com"
                emailItem.CC = selfEmail
                emailItem.Subject = SubTitle
                emailItem.Body = "See attached interest form."
                emailItem.Attachments.Add ActiveWorkbook.FullName
                emailItem.Send
                VBA.Interaction.MsgBox "Your submission has been received! Thank you.", , "Submission Confirmation"
                Set emailItem = Nothing
                Set emailApp = Nothing
            Else
                Exit Sub
        End If
        
    End Sub
    The error message I get is:
    Error.jpg

    When I click Debug, the following line of code is highlighted:

    Code.jpg


    Any ideas on why this line of code is being flagged? I have added the Outlook 15.0 object library to this project. Thanks

  2. #2
    If you look at your debug screen shot, the email 'address' at the top of the listed code emailItem.to or the value of 'selfemail' are not valid e-mail addresses. My guess is the latter.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Feb 2018
    Location
    Portland
    Posts
    26
    Location
    Hello gmayor, that is all it was. My value for the variable "selfEmail" was invalid. I was looking for a more "complicated" reason why code wasn't working. The error message led me down the wrong path. Simple coding mistake. I appreciate your time. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •