darbid
darbid

Reputation: 2731

Why does CreateObject("Outlook.Application") cause an exception but still start Outlook 2007 with the embedding switch?

I am using what I thought was a pretty standard practice to do some Outlook 2007 automation on a Windows 7 x64 PC.

I call GetObject(, "Outlook.Application") and if this raises an exception, then I call CreateObject("Outlook.Application").

The issue is that CreateObject("Outlook.Application") now raises an "Cannot create ActiveX component." exception but Outlook is started as a process in Task Manager. I can see it with "-Embedding" after it which I understand is normal for co-create.

Once this is running GetObject(, "Outlook.Application") will still fail but CreateObject("Outlook.Application") does not.

This means my hack would be...

GetObject(, "Outlook.Application"), Catch Exception, CreateObject("Outlook.Application"), Catch Exception, CreateObject("Outlook.Application"), off we go with some automation.

Has anyone else experienced this, or is there something else I should be checking.

Upvotes: 1

Views: 1303

Answers (3)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

Do not use GetObject with Outlook - it is a singleton, so CreateObject will return a pointer to the running instance.

Upvotes: 0

Chris Raisin
Chris Raisin

Reputation: 442

The solution to this is to run your Visual Studio IDE under "Administrator" privileges. Just change the security setting in the IDE Icon on the desktop under "Properties" to "Adminstrator" and restart your IDE.

Upvotes: 0

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

It looks like something is wrong with your windows regisrty keys. This behavior can occur if the following registry keys are missing or incomplete:

HKEY_CLASSES_ROOT\Outlook.Application

HKEY_CLASSES_ROOT\Interface\{000C0339-0000-0000-C000-000000000046}

Note, on machines with a 32-bit version of Office and a 64-bit version of Windows, the above keypath is instead:

HKEY_CLASSES_ROOT\Wow6432Node\Interface\{000C0339-0000-0000-C000-000000000046}

See Missing registry information can cause problems with the Outlook object model for more information.

Upvotes: 0

Related Questions