Type Mismatch using .SendUsingAccount in a Mail item

Paul Alford

New Member
Joined
Sep 21, 2009
Messages
18
Hi,

I am getting a VBA type mismatch error in Excel 2007 with the following code at the line .SendUsingAccount and I can't seem to find a solution to the problem. It's driving me nuts. Without this line emails are created and sent perfectly from the default mail account in Outlook 2007, but when I add the line of code to select a different account it keels over.

Below is the code.

Can anyone point me in the right direction please?

Code:
Dim AccountToSendFrom As String
AccountToSendFrom = "john.doe@acme.com"

With MItem
        .To = IntEmail
        .Subject = Msg2
        .Body = Msg
        .SendUsingAccount = AccountToSendFrom
End With
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
After a lot of digging around I found this buried in a forum. The bold line executes, but the email still sends from the default mail account.

So now I have the following code - any ideas?

Thanks.


Code:
Dim OutlookApp As Outlook.Application
Dim MItem As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set MItem = OutlookApp.CreateItem(olMailItem)

With MItem
        .To = IntEmail
        .Subject = Msg2
        .Body = Msg
        .SendUsingAccount = OutlookNamespace.Accounts("Account Name")

End With
 
Upvote 0

Forum statistics

Threads
1,226,039
Messages
6,188,526
Members
453,481
Latest member
Peolini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top