0

This is code to send emails from an Excel file.

I want to choose the Outlook account from which the emails are sent ("abc@abc.com").

Sub SendEmail()
Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set Mail_Object = CreateObject("Outlook.Application")
For i = 2 To lr
    With Mail_Object.CreateItem(o)
        .Subject = Range("B" & i).Value
        .To = Range("A" & i).Value
        .Body = Range("C" & i).Value
        '.CC = Range("G" & i).Value
        '.Send
        .display 'disable display and enable send to send automatically
    End With
Next i
MsgBox "E-mail successfully sent", 64
Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
Community
  • 1
  • 1
  • Does this answer your question? [How to send email from a specific Outlook account using Excel?](https://stackoverflow.com/questions/55360867/how-to-send-email-from-a-specific-outlook-account-using-excel) – niton Jul 30 '22 at 03:00

1 Answers1

1

I think you're after the SentOnBehalfOfName property:

With Mail_Object.CreateItem(o)
    .Subject = Range("B" & i).Value
    .To = Range("A" & i).Value
    .Body = Range("C" & i).Value
    .SentOnBehalfOfName = "abc@abc.com"
    '.CC = Range("G" & i).Value
    '.Send
    .display 'disable display and enable send to send automatically
End With
CLR
  • 11,284
  • 1
  • 11
  • 29