Reputation: 1
I need help to find a way to change the e-mail with which email will be sent using VBA. Below is my current code and emails are being sent with my e-mail and i need to change it to group email id.
Dim olApp As Object
Dim olMail As Object
Dim olRecip As Object
Dim olAtmt As Object
Dim iRow As Long
Dim Recip As String
Dim Subject As String
Dim Atmt As String
Dim sMsgBody As String
Dim strfrom As String
iRow = 2
Set olApp = CreateObject("Outlook.Application")
Dim Sht As Worksheet
Set Sht = ThisWorkbook.Worksheets("Sheet1")
Do Until IsEmpty(Sht.Cells(iRow, 1))
Recip = Sht.Cells(iRow, 1).Value
Subject = Sht.Cells(iRow, 2).Value
Atmt = Sht.Cells(iRow, 3).Value ' Attachment Path
Set olMail = olApp.CreateItem(0)
With olMail
Set olRecip = .Recipients.Add(Recip)
.Subject = Subject
.body = sMsgBody
.Display
.
Set olAtmt = .Attachments.Add(Atmt)
olRecip.Resolve
End With
iRow = iRow + 1
Loop
Set olApp = Nothing
Upvotes: 0
Views: 264
Reputation: 10226
If you want to change the sender account, use the Sender property
If you want to send it with your own account but with a different mail address, use SentOnBehalfOfName property. That's what I usually do.
With olMail
Set olRecip = .Recipients.Add(Recip)
' chose either :
.Sender = "[email protected]"
' or
.SentOnBehalfOfName = "[email protected]"
Upvotes: 1