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.
|