Can Not Automate Outlook From Excel

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Outllook 2003 on XP Pro

I am trying to open Outlook and crate a message from Excel VBA module and I
am getting the following error

The Operation failed. - -2147287037: In RunExportProgram Function

(Every thing works fine if Outlook is already open, but not when it's
closed)
The same code works fine on other computers even when Outlook is closed.


Here's the code:

Dim OutlookApp As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set Message = OutlookApp.Application.CreateItem(0) ' <-- This is where
the error occurs



Thanks


Peter
 
The cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. If so, the solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)

Also, you can simplify your statement creating a new message to:

Set Message = OutlookApp.CreateItem(0)
 
The cause may be an anti-virus program on your computer that has a feature
to block Outlook scripting. If so, the solution is to turn off the script
blocking feature. You may need to contact technical support for your
anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this
problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)

Also, you can simplify your statement creating a new message to:

Set Message = OutlookApp.CreateItem(0)

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Peter said:
Outllook 2003 on XP Pro

I am trying to open Outlook and crate a message from Excel VBA module and
I
am getting the following error

The Operation failed. - -2147287037: In RunExportProgram Function

(Every thing works fine if Outlook is already open, but not when it's
closed)
The same code works fine on other computers even when Outlook is closed.


Here's the code:

Dim OutlookApp As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set Message = OutlookApp.Application.CreateItem(0) ' <-- This is where
the error occurs



Thanks


Peter

I have not tried the Antivirus thing yet because I don't have access to the
specific computer at this time, but when try

Set ol = CreateObject("Outlook.Applicaton", "localhost")
or
Set ol = CreateObject("Outlook.Applicaton", "<actual-name.domain.com>")

I get the following error on a computer that Outlook does open by the code.
 
I have disabled the Anti Virus program and still getting the same error
message. (I've stopped or disabled as many programs as I could, but the
error persists).
What else can I check or try?


Thank You
 
Did you try the alternate version of the CreateObject expression? Does the expression OutApp Is Nothing return True? Does the VBA environment have a reference set to the Microsoft Outlook library?
 
Here's the updated code:

Dim OutlookApp As Object
Dim Message As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set Message = OutlookApp.CreateItem(0) ' <== fails here

Message.Display
''''

'OutlookApp Is Nothing' returns False

VBA environment does not set reference to Outlook library, because I am
using late binding. I have tried setting the reference and using early
binding code, but got the same error.
The same code works fine when Outlook is already running, but fails when
Outlook is not started.

I have found this this error description: -2147287037 (80030003) The path %1
could not be found.

But path to what? It can not be path to Outlook executable, because the
Outlook does load into memory after executing Set OutlookApp =
CreateObject("Outlook.Application") statement. but it disappears from memory
after Set Message = OutlookApp.CreateItem(0) statement.



Did you try the alternate version of the CreateObject expression? Does the
expression OutApp Is Nothing return True? Does the VBA environment have a
reference set to the Microsoft Outlook library?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Peter said:
I have disabled the Anti Virus program and still getting the same error
message. (I've stopped or disabled as many programs as I could, but the
error persists).
What else can I check or try?
 
Try adding statements to log onto the desired mail profile:

Set ns = OutlookApp.GetNamespace("MAPI")
ns.Logon "name of profile

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Peter said:
Here's the updated code:

Dim OutlookApp As Object
Dim Message As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set Message = OutlookApp.CreateItem(0) ' <== fails here

Message.Display
''''

'OutlookApp Is Nothing' returns False

VBA environment does not set reference to Outlook library, because I am
using late binding. I have tried setting the reference and using early
binding code, but got the same error.
The same code works fine when Outlook is already running, but fails when
Outlook is not started.

I have found this this error description: -2147287037 (80030003) The path %1
could not be found.

But path to what? It can not be path to Outlook executable, because the
Outlook does load into memory after executing Set OutlookApp =
CreateObject("Outlook.Application") statement. but it disappears from memory
after Set Message = OutlookApp.CreateItem(0) statement.



Did you try the alternate version of the CreateObject expression? Does the
expression OutApp Is Nothing return True? Does the VBA environment have a
reference set to the Microsoft Outlook library?

Peter said:
I have disabled the Anti Virus program and still getting the same error
message. (I've stopped or disabled as many programs as I could, but the
error persists).
What else can I check or try?
 
Back
Top