Creating an Outlook MailItem when Outlook hasn't been opened

W

WhytheQ

This is a mystery to me!

If I run the below code from an Excel module when Outlook is shut it
throws a error:
"Run-time error' '-214787037 (80030003)' Internal application error"

Dim OutApp2 As Object
Dim OutMail2 As Object

On Error Resume Next
Set OutApp2 = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set OutApp2 = CreateObject("Outlook.Application")
End If
On Error GoTo 0

Set OutMail2 = OutApp2.CreateItem(0)

If I run the above but replace the last line with the following:
Set OutMail2 =
OutApp2.CreateItemFromTemplate("InsertPathwayToTemplate.msg")
......then everything is ok.

Anybody seen this before?
Any help greatly appreciated
Jason
 
D

Dmitry Streblechenko

See adding the following code after CreateObject() will help:

set NS = OutApp2.GetNamespace("MAPI")
NS.Logon

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top