User-defined type not defined when sending email using Excel.

amitcohen

Board Regular
Joined
Jan 14, 2010
Messages
118
Hi

I have found this macro (http://www.slipstick.com/outlook/2010/multiple-accounts-and-the-default-account/)
Code:
'Sub Mail_small_Text_Change_Account()
Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
 
For Each oAccount In Application.Session.Accounts
   If oAccount = "me@mywebsite.com" Then
      Set oMail = Application.CreateItem(olMailItem)
      oMail.SendUsingAccount = oAccount
      oMail.Display
   End If
Next
End Sub
This allow me to select the account for sending email other then the default one.

However, when running the macro, I'm getting the compile error: User-defined type not defined.

I did activated the 'Microsoft DAO n3.6 Object Library.

And yet, still giving me that error..


Any ideas how to solve this?

Thanks,
Amit.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Did you try adding a reference in the VB Editor to the Microsoft Outlook 12.0 Object Library too? (Might be 14.0 if you're also using Outlook 2010.)
 
Upvote 0
Hi mvptomlinson
I have added the 'Microsoft Outlook 12.0 Object Library'

But now, its giving me the 'Run time error 438
Object doesn't support this property or method.
(VBA editor highlights the code row of:
Code:
For Each oAccount In Application.Session.Accounts
Maybe there is a problem with the whole macro..?
 
Upvote 0
My guess is in this case "Application" is meant to refer to the Outlook application, not Excel. Unfortunately, the macro doesn't include any reference to the current or newly created outlook application. Usually you would use something like
Code:
Dim outApp as Outlook.Application
Set outApp = New Outlook.Application
...
And then replace "Application" with "outApp" (no quotes, of course).
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

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