Use VBA to send email from a shared Outlook account

0

I have a simple VBA script to cycle through a list of email addresses in Excel and send email with individual attachments. This works fine, and emails are sent from my primary/default account that is tied to the exchange server which is the same account that I use to login to my company's PC. I have access to another shared outlook account and I can see both my personal and the shared account in outlook. How can i change the below VBA script to send emails from the shared account. In other words, is there a way to specify a specific email account to open and send emails using this script?

Dim sh As Worksheet
Dim OA As Object, msg As Object
Dim i As Integer, j As Integer

Set sh = ThisWorkbook.Sheets("Sheet1")
Set OA = CreateObject("Outlook.Application")
j = Application.WorksheetFunction.CountA(sh.Range("A:A"))

For i = 2 To j
    Set msg = OA.CreateItem(0)

    msg.To = sh.Range("A" & i).Value
    msg.cc = sh.Range("B" & i).Value
    msg.Subject = sh.Range("C" & i).Value
    msg.Body = sh.Range("D" & i).Value
    If sh.Range("E" & i).Value <> "" Then
        msg.attachments.Add sh.Range("E" & i).Value
    End If

    msg.send
Next i

Andy

Posted 2019-11-07T19:03:11.303

Reputation: 1

Answers

0

From Outlook help on MailItem.Sender: https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.sender

Remarks

In a session where multiple accounts are defined in the profile, you can set this property to specify the account from which to send a mail item. Set this property to the AddressEntry object of the user that is represented by the CurrentUser property of a specific account.

SmileyFtW

Posted 2019-11-07T19:03:11.303

Reputation: 101