0
votes

until Outlook 2013, I was able to send new messages using a specific IMAP Account through macros.

Since Outlook 2016, I've got an error message : "Run-Time error '9': Subscript out of range"

here is the code:

Sub createMailIMAP()
    Dim MyMail As MailItem, _
        olkInspector As Outlook.Inspector, _
        olkSendThroughBtn As CommandBarPopup, _
        olkSendAccount As CommandBarButton
    Set MyMail = Application.CreateItem(olMailItem)
    MyMail.BodyFormat = olFormatPlain
    MyMail.Body = ""
    MyMail.Display
    Set olkSendThroughBtn = Application.ActiveInspector.CommandBars("Standard").Controls(3)
    Set olkSendAccount = olkSendThroughBtn.Controls(2)
    olkSendAccount.Execute
End Sub

Nota bene: The outlook is configured with Exchange account and has an additional shared mailbox.

Does this code is deprecated for Outlook 2016? Cheers poy.

1

1 Answers

0
votes

Controls collection is now empty (Controls.Count == 0). - Outlook 2016 uses ribbons.

Set the MailItem.SendUsingAccount property instead.