简体   繁体   中英

How to change email id in from field in outlook

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

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 = "anything@yourcompany.com"
    ' or
    .SentOnBehalfOfName = "anything@yourcompany.com"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM