Error on CreateObject("Outlook.Application")

R

Randy Elliott

Good Day,
I have an application running in Outlook that receives emails
from a form on a website, parses the data, stores it in an Access
database and then files each email message in a sub-folder, depending
on the subject line. In operation, I leave Outlook running at all
times and Access closed. Other individuals (Marketing people) view
and edit the data via an aspx page (IIS is running on this machine).
The entire process worked fine on a Windows 2000 machine running
Office Pro 2000, but when I moved it to a new XP Pro machine with
Office Pro 2003 (my desktop computer, used for other tasks as well -
2.8 GHz, 1 GB RAM) it no longer functioned. I solved most of the
problems with the database, IIS and the ASP.NET code to view database
contents, but the process is failing near the beginning, on the
CreateObject("Outlook.Application") line.
The problem code section follows:
-------------------------------------
Private Sub Application_NewMail()

Dim webInbox As Outlook.MAPIFolder
Dim namespace1 As NameSpace
Dim messages As Outlook.Items
Dim oneMessage As Outlook.MailItem

Dim strBody, submittedName, submittedEmail, submittedTitle, _
submittedUniversity, submittedAddress1, submittedAddress2,
submittedCity, _
[and several other variables] As String

Dim objOutlook As Outlook.Application

MsgBox ("Now have variables declared ")
Set objOutlook = CreateObject("Outlook.Application")
MsgBox ("objOutlook is set")
--------------------------

In operation, I get the first message box, click "OK" and then a
dialog box pops up with

Run-time error '-xxx(yyy7007e)':
[where xxx is an 8 to 10 digit number and yyy is 3 hex
characters]
The operation failed

At this point, clicking OK dismisses the box while clicking HELP
brings up Visual Basic Help opened to the "Automation error (Error
440)" page.

My troubleshooting so far has been
1. Substitute "Word.Application" and "Excel.Application" (both work
fine),
2. Ensuring that proper references are set (compared to those on the
Win2k box)
VBA
Outlook 11.0 Object Library
OLE Automation
MS Office 11.0 Object Library
MS Access 11.0 Object Library
MS DAO 3.6 Object Library
[and no others]
are all checked
3. Editing registry entry
[HKEY_CLASSES_ROOT\CLSID\{0006F03A-0000-0000-C000-000000000046}]
@="Microsoft Office Outlook" to change @="C:\\Program Files\\Common
Files\\Symantec Shared\\Script Blocking\\ScrBlock.dll"
[not sure how that got in there, changed it to
C:\WINNT\System32\scrrun.dll]

4. Reinstalling (fix) Office
5. Windows Update on Office

Although I don't think it matters, it may be notable that I did
change the machine name after most of the software was loaded.

I think I must be missing something really trivial here, but have
been pulling my hair out for several days. Any suggestions would be
really appreciated.

--Randy
 
S

Sue Mosher [MVP-Outlook]

If this is Outlook VBA code, use the intrinsic Application object instead of
CreateObject.
 
R

Randy Elliott

Sue,
Thanks - it is indeed VBA imbedded in Outlook and your suggestion
solved my problem. After doing some searching on "intrinsic
Application Object" on several websites and in this newsgroup (mainly
previous postings by you and by Ken Slovak) I made the following
changes:

ORIGINAL
Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
Set namespace1 = objOutlook.GetNamespace("MAPI")

REVISED VERSION
Set namespace1 = Application.GetNamespace("MAPI")

. . . and now it works.

Thanks again,

Randy Elliott

Sue Mosher said:
If this is Outlook VBA code, use the intrinsic Application object instead of
CreateObject.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Randy Elliott said:
Good Day,
I have an application running in Outlook that receives emails
from a form on a website, parses the data, stores it in an Access
database and then files each email message in a sub-folder, depending
on the subject line. In operation, I leave Outlook running at all
times and Access closed. Other individuals (Marketing people) view
and edit the data via an aspx page (IIS is running on this machine).
The entire process worked fine on a Windows 2000 machine running
Office Pro 2000, but when I moved it to a new XP Pro machine with
Office Pro 2003 (my desktop computer, used for other tasks as well -
2.8 GHz, 1 GB RAM) it no longer functioned. I solved most of the
problems with the database, IIS and the ASP.NET code to view database
contents, but the process is failing near the beginning, on the
CreateObject("Outlook.Application") line.
The problem code section follows:
-------------------------------------
Private Sub Application_NewMail()

Dim webInbox As Outlook.MAPIFolder
Dim namespace1 As NameSpace
Dim messages As Outlook.Items
Dim oneMessage As Outlook.MailItem

Dim strBody, submittedName, submittedEmail, submittedTitle, _
submittedUniversity, submittedAddress1, submittedAddress2,
submittedCity, _
[and several other variables] As String

Dim objOutlook As Outlook.Application

MsgBox ("Now have variables declared ")
Set objOutlook = CreateObject("Outlook.Application")
MsgBox ("objOutlook is set")
--------------------------

In operation, I get the first message box, click "OK" and then a
dialog box pops up with

Run-time error '-xxx(yyy7007e)':
 
P

Peter Herbison

Thanks Folks. I had exactly the same problem and this fix
worked for me also.

Interestingly, the sample in the help file under the
ActiveInspector Method called DisplayKeys() also uses
CreateObject and also causes trouble.

It doesn't help when the samples are also incorrect.
-----Original Message-----
Sue,
Thanks - it is indeed VBA imbedded in Outlook and your suggestion
solved my problem. After doing some searching on "intrinsic
Application Object" on several websites and in this newsgroup (mainly
previous postings by you and by Ken Slovak) I made the following
changes:

ORIGINAL
Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
Set namespace1 = objOutlook.GetNamespace("MAPI")

REVISED VERSION
Set namespace1 = Application.GetNamespace("MAPI")

. . . and now it works.

Thanks again,

Randy Elliott

"Sue Mosher [MVP-Outlook]" <[email protected]>
wrote in message
If this is Outlook VBA code, use the intrinsic Application object instead of
CreateObject.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Good Day,
I have an application running in Outlook that receives emails
from a form on a website, parses the data, stores it in an Access
database and then files each email message in a sub- folder, depending
on the subject line. In operation, I leave Outlook running at all
times and Access closed. Other individuals (Marketing people) view
and edit the data via an aspx page (IIS is running on this machine).
The entire process worked fine on a Windows 2000 machine running
Office Pro 2000, but when I moved it to a new XP Pro machine with
Office Pro 2003 (my desktop computer, used for other tasks as well -
2.8 GHz, 1 GB RAM) it no longer functioned. I solved most of the
problems with the database, IIS and the ASP.NET code to view database
contents, but the process is failing near the beginning, on the
CreateObject("Outlook.Application") line.
The problem code section follows:
-------------------------------------
Private Sub Application_NewMail()

Dim webInbox As Outlook.MAPIFolder
Dim namespace1 As NameSpace
Dim messages As Outlook.Items
Dim oneMessage As Outlook.MailItem

Dim strBody, submittedName, submittedEmail, submittedTitle, _
submittedUniversity, submittedAddress1, submittedAddress2,
submittedCity, _
[and several other variables] As String

Dim objOutlook As Outlook.Application

MsgBox ("Now have variables declared ")
Set objOutlook = CreateObject("Outlook.Application")
MsgBox ("objOutlook is set")
--------------------------

In operation, I get the first message box, click "OK" and then a
dialog box pops up with

Run-time error '-xxx(yyy7007e)':
.
 
S

Sue Mosher [MVP-Outlook]

There are two issues at play here: One is that the samples are written to be
generic and to apply to all VBA and even VB environments. The intrinsic
Application object is available only in the Outlook VBA environment. The
other is that certain anti-virus programs include script blockers that
specifically block calls to CreateObject("Outlook.Application"). Unless you
know that's a likely cause, you're not going to go looking in your
anti-virus program for the setting to turn off that blocker.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Peter Herbison said:
Thanks Folks. I had exactly the same problem and this fix
worked for me also.

Interestingly, the sample in the help file under the
ActiveInspector Method called DisplayKeys() also uses
CreateObject and also causes trouble.

It doesn't help when the samples are also incorrect.
-----Original Message-----
Sue,
Thanks - it is indeed VBA imbedded in Outlook and your suggestion
solved my problem. After doing some searching on "intrinsic
Application Object" on several websites and in this newsgroup (mainly
previous postings by you and by Ken Slovak) I made the following
changes:

ORIGINAL
Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
Set namespace1 = objOutlook.GetNamespace("MAPI")

REVISED VERSION
Set namespace1 = Application.GetNamespace("MAPI")

. . . and now it works.

Thanks again,

Randy Elliott

"Sue Mosher [MVP-Outlook]" <[email protected]>
wrote in message
 

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