Set the FROM Address when sending emails from excel

damaniam1604

New Member
Joined
Sep 12, 2018
Messages
20
Hi all.

I wanted to first say thank you to everyone on here who has helped me in the past. I am very grateful.

My issue: I have some VBA code that I run from Excel. It works as desired, except for the email address from which the emails are being sent. I'd like to avoid the SentOnBehalfOf because I want the emails to be in the sent folder of the desired FROM email address.

VBA Code:
Sub Macro1()

    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object
    Dim r As Long

    Set rng = ActiveSheet.UsedRange

    r = 3   ' This # indicates the first row of applicable data
    
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutAccount = OutApp.Session.Accounts.Item(3)

    Do While r <= rng.Rows.Count
        Set OutMail = OutApp.CreateItem(0)
       
       With OutMail
           
            .To = rng.Cells(r, 6).Value
            .Subject = rng.Cells(r, 7).Value
            .htmlbody = rng.Cells(r, 8).Value
            .Attachments.Add (rng.Cells(r, 10).Value)
            
             .Display
            'or
             'Use display to show messages without sending. Use Send to immediately send message
            
            '.send
            
        End With
       
        Set OutMail = Nothing
        r = r + 1
    Loop
    Set OutApp = Nothing
    Set OutAccount = Nothing
    

End Sub

Thanks in advance for your assistance,

Jordan
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Have you tried to use SendUsingAccount instead of SentOnBehalfOfName ?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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