Outlook Does not recognize one or more names

Joined
Mar 3, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have this macro to mail individual mail to my recipients with attachment. I have not altered this macro and it have worked up til now. I cannot find any error in my mail-addresses either. Any suggestions what to look for?


2021-06-28_10-42-18.png



VBA Code:
Sub Email_From_Excel_Attachments()

    Dim emailApplication    As Object, emailItem As Object
    Dim cell                As Range, rng        As Range
    
    On Error GoTo myerror
    Set emailApplication = CreateObject("Outlook.Application")
    
    With Sheets("Adresses")
        lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row - 1
        Set rng = .Cells(2, 2).Resize(lastrow, 1)
    End With
    
    For Each cell In rng.Cells
        Set emailItem = emailApplication.CreateItem(0)
    
        With emailItem
            .To = cell.Value
            .cc = cell.Offset(, 1).Value
            .Subject = cell.Offset(, 2).Value & Date
            .Body = cell.Offset(, 3).Value
            .Attachments.Add cell.Offset(, 4).Value
            .Send
        End With
        Set emailItem = Nothing
    Next cell
myerror:
    If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Disable your error handler temporarily so that you can debug when the error occurs. Then you'll know which name(s) to check.
 
Upvote 0
An error in the email addresses/recipient names, judging by the error message.
 
Upvote 0
Ok, I narrowed it down to two email addresses. They look correct and I have even pasted them in again in my excel-sheet just to be sure they are correct. They Work when I paste them directly into outlook but not when copied from my excel sheet / macro. Is there any way that these cells are copy protected or something? Could there be some cells are locked in my sheet?
 
Upvote 0
You're not copying anything so I don't see how that could be an issue. Try reinstating your error handler, but after the Msgbox line, put:

Code:
emailItem.Display
and check what is in the To field.
 
Upvote 0
You're not copying anything so I don't see how that could be an issue. Try reinstating your error handler, but after the Msgbox line, put:

Code:
emailItem.Display
and check what is in the To field.
Aha! Now I see the problem (I think). Outlook is changing the email-adress to the recipiants name since I have in in my adress book. When I did this extra step it had time to actually do this befor trying to send. You understand what I mean? Big thanks!

Just one more question now :-) How do I make sure that example@ex.xx works and don't need to be changed to Name. Name in outlok?
 
Upvote 0
A literal email address should work regardless of whether it exists in your contacts. Can you actually send the email immediately after it displays?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top