|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Error when sending email from Excel using an Outlook.account identified by its email address.
I send email from within Excel where I determine which of a number of outlook accounts should be used to send the mail. I have always done this using early binding and I have no problem, however I am currently knocking up a workbook where I want to use late binding and have encountered a problem.
Identifying the account by it's account number works in both early and late binding. Identifying the account from it's email address works in early binding but fails in late binding. Early Binding works fine as in the two following procedures: Sub EarlyBindingChangeAccountByNumber() Dim OutApp As Outlook.application Dim OutMail As Outlook.MailItem Dim OutAccount As Outlook.account Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(olMailItem) Set OutAccount = OutApp.Session.accounts.Item(1) With OutMail .SendUsingAccount = OutAccount .Display End With End Sub Sub EarlyBindingChangeAccountByName() Dim OutApp As Outlook.application Dim OutMail As Outlook.MailItem Dim OutAccount As Outlook.account Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(olMailItem) Set OutAccount = OutApp.Session.accounts("myaddress@gmail.com") With OutMail .SendUsingAccount = OutAccount .Display End With End Sub Late binding works fine in the first of the following procedures but not in the second. Sub LateBindingChangeAccountByNumber() Dim OutApp As Object Dim OutMail As Object Dim OutAccount As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Set OutAccount = OutApp.Session.accounts.Item(1) With OutMail Set .SendUsingAccount = OutAccount .Display End With End Sub However I get this error on the Set OutAccount line when i specify the email address for the account. Run-time error '450': Wrong number of arguments or invalid property assignment Sub LateBindingChangeAccountByName() Dim OutApp As Object Dim OutMail As Object Dim OutAccount As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Set OutAccount = OutApp.Session.accounts("myaddress@gmail.com") With OutMail Set .SendUsingAccount = OutAccount .Display End With End Sub Any enlightement on this would be gratefully recieved. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
change from address when sending email | kitelooper | Outlook | 7 | 02-14-2020 01:53 AM |
when sending email pick email address 1 2 or 3 from the person contact. | red_dog2 | Outlook | 1 | 06-15-2017 07:56 PM |
How to prevent exchange email account from sending emails in Outlook | igii05 | Outlook | 0 | 01-24-2014 05:37 PM |
outlook - sending/replying with second email on account | smitty0476 | Outlook | 0 | 08-08-2013 09:49 AM |
outlook.com account in Outlook 2007 freezes at 93% sending/receiving email | ink8 | Outlook | 0 | 10-10-2012 12:19 PM |