Le Café Central de Deva
..... Deva blogs!!
Recently one of my developer customer migrated from Outlook 2003 to 2010. He tried running the custom application (uses CDO & Outlook 2003) in Outlook 2010. It throws the error “ActiveX component can’t create object”. Using the following test sample, I can reproduce the exact issue at my end:
As you know, Microsoft Outlook 2010 includes many architectural changes to the client-side MAPI subsystem. Of particular concern are scenarios in which Outlook is configured to use multiple Exchange accounts. Also, CDO 1.2.1 is a 32-bit client library and will not operate with 64-bit Outlook 2010. Given all these factors, CDO 1.2.1 is not supported for use with Outlook 2010 and we don’t recommend its usage with Outlook 2010. As updated earlier, in Outlook 2010 you need to re-write/migrate the code base referencing CDO to Outlook Object Model or MAPI, messaging libraries which ever suits you. So the programs/custom applications that use CDO should be re-designed to use other Application Programming Interfaces (APIs) instead of CDO. Starting with Outlook 2007, the Outlook object model was greatly expanded to provide functionality that was previously available only by using CDO 1.2.1. The Outlook 2010 object model includes some new features to expand on this more. For example, the Outlook 2010 object model has new functionality to operate correctly with multiple Exchange accounts. The Outlook object model also works for both 32-bit and 64-bit versions of Outlook. Developers should use the Outlook 2010 object model instead of CDO 1.2.1. Also, developers can still use Extended MAPI (which requires unmanaged C++) in some scenarios where CDO was required. However, if it is possible, we generally recommend that the Outlook object model be used instead of Extended MAPI.
In this post, we will take the above code sample and will show how you can migrate/re-write the CDO based application to Outlook Object Model library.
1: Dim MapiSession As Object
2: Dim MapiMessage As Object
6: Set MapiSession = CreateObject("Mapi.Session") ' Create the MAPI Session.
8: MapiSession.Logon , , , False ' Log on to the session.
10: Set MapiMessage = MapiSession.Outbox.Messages.Add
12: With MapiMessage
13: .To = "firstname.lastname@example.org"
14: .Subject = "Test"
15: .Text = "Test"
16: .send showdialog:=True
17: End With
21: Set MapiSession = Nothing ' Clear the object variable.
Once you done with migration, the OOM code (created in Outlook 2010) will look like the below:
1: Dim MapiSession As Outlook.Application
2: Dim MapiMessage As Outlook.MailItem
4: Set MapiSession = CreateObject("Outlook.Application") ' Create the MAPI Session.
5: MapiSession.GetNamespace("MAPI").Logon , , , False
7: Set MapiMessage = MapiSession.CreateItem(olMailItem)
8: With MapiMessage
9: .To = "email@example.com"
10: .Subject = "Test"
11: .Body = "Test"
13: End With
15: Set MapiSession = Nothing
Please note: Microsoft product support can help developer customers migrate custom programs from using CDO 1.2.1 to using other APIs. However, Microsoft will not provide support for any scenarios in which CDO 1.2.1 is used with Outlook 2010.
Hey Dev guy, Where were you till the time. I just saw this article; Nice one, earlier i struggled this similar CDO application. Later when i learnt that there is no support on this. Now i got a way to move ahead. Nice one, bro.
Is it possible to connect to another user's mailbox using this code with Windows 7 and Office 2010? It worked with XP and 2010 but now we get invalid parameter messages.
strMAPI = strExchangeSvr & vbLf & strUserName
objMAPISession.Logon "", "", False, True, 0, False, strMAPI
i used the below code to automate my out of office but this is giving object required error. could someone please assist me on this as its a bit urgent.
Private Sub Application_Quit()
Dim objMAPISession As Outlook.Application
Dim StartDate As Date
Set objReminders = Nothing
If MsgBox("Would you like to turn the Out of Office Assistant on?", vbYesNo, "Activate Out of Office Assistant") = vbYes Then
Set objMAPISession = CreateObject("Outlook.Application")
objMAPISession.Logon , , , False
objMAPISession.OutOfOffice = True
If objMAPISession.OutOfOffice = True Then
StartDate = CDate(InputBox("Enter the date, " & "in the format: mm/dd/yyyy"))
objMAPISession.OutOfOfficeText = "Hi,"
Set objMAPISession = Nothing