Auto changing the Email .SentOnBehalfOfName doesnt change the from section

gruntingmonkey

Active Member
Joined
Mar 6, 2008
Messages
434
Office Version
  1. 365
Platform
  1. Windows
I am trying to change the send from address when creating an email through VBA but can't seem to manage it. I have added " .SentOnBehalfOfName = "Test@Test.com"" but it doesnt change it in the email that it pops up.

VBA Code:
Sub SendFileTESTVERSION()

 On Error GoTo ErrHandler
    '''creates the email with details

    ' SET Outlook APPLICATION OBJECT.
    Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    
    ' CREATE EMAIL OBJECT.
    Dim objEmail As Object
    Set objEmail = objOutlook.CreateItem(olMailItem)
    
    Datestamp = Format(Date, "mmm yyyy")
    strbody = "Hello all," & _
              "<br><br>Please find attached the Dashboard for " & Datestamp & "." & _
              "<br><br>Kind regards,"
              
    EmailTo = Worksheets("Utilities").Cells(14, 4).Value
    Filept = "C:\Test\"
    FileNm = "Dashboard.xlsx"
    attfile1 = Filept + FileNm

'''Create email
    On Error Resume Next
    With objEmail
        .Display
        .SentOnBehalfOfName = "Test@Test.com"
        .To = EmailTo
        .Subject = "Dashboard for " & Datestamp & ""
        .HTMLBody = strbody & "<br>" & .HTMLBody
        .attachments.Add attfile1
        '.send
        .Display
    End With
    
     Set objEmail = Nothing:    Set objOutlook = Nothing
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

Sheets("Utilities").Activate

Sheets("Utilities").Select
Cells(13, 3).Value = "Complete"

Exit Sub

ErrHandler:
MsgBox "There has been an error"
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Works for me. Try without using the line On Error Resume Next while testing and see if your macro throws an error for that parameter.
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,992
Members
449,094
Latest member
masterms

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