CreateObject(), GetObject() question

Status
Not open for further replies.
S

Salad

I have the following sub

Sub test()

'it doesn't matter which of these I use.

Dim olApp As Object

'Dim olApp As Outlook.Application

'always a (8007007e) error with following line.

'Set olApp = CreateObject("Outlook.Application")

'never get an error as long as Outlook is open

Set olApp = GetObject(, "Outlook.Application")

Set olApp = Nothing

MsgBox "Done"

End Sub

I have a reference set to Microsoft Outlook Object Library.

I commented out the CreateObject() line because I get a runtime error

(8007007e) "Automation Error: The specified model could not be found."

It works with the GetObject() line...but only if Outlook is open. If

Outlook is closed, I get an runtime error 429 "ActiveX can't create

object. Is this normal?

Any idea of what is wrong?
 
Does the code run in Outlook? Then don't use any of the methods; there's

already an Application object, which you should use.

Both methods are only used if you want to access an application from

outside. For instance, from Outlook you could use CreateObject to start a

new instance of Excel, or use GetObject to access a running instance of

Excel.

Best regards

Michael Bauer

Am Fri, 19 Feb 2010 18:05:01 -0800 schrieb Salad:


> I have the following sub
> Sub test()
> 'it doesn't matter which of these I use.
> Dim olApp As Object
> 'Dim olApp As Outlook.Application

> 'always a (8007007e) error with following line.
> 'Set olApp = CreateObject("Outlook.Application")

> 'never get an error as long as Outlook is open
> Set olApp = GetObject(, "Outlook.Application")
> Set olApp = Nothing
> MsgBox "Done"
> End Sub

> I have a reference set to Microsoft Outlook Object Library.

> I commented out the CreateObject() line because I get a runtime error
> (8007007e) "Automation Error: The specified model could not be found."

> It works with the GetObject() line...but only if Outlook is open. If
> Outlook is closed, I get an runtime error 429 "ActiveX can't create
> object. Is this normal?

> Any idea of what is wrong?
 
Michael Bauer wrote:


> Does the code run in Outlook? Then don't use any of the methods; there's
> already an Application object, which you should use.

> Both methods are only used if you want to access an application from
> outside. For instance, from Outlook you could use CreateObject to start a
> new instance of Excel, or use GetObject to access a running instance of
> Excel.
>


Hi Michael, Thanks for your response.

I was excited with your response when you mentioned the Application

object but got crushed when you mentioned that GetObject/CreateObject

were used from an external app. And that's the case...I am running it

from Access 2003 and setting the object for Outlook 2003. I should have

mentioned that in the original post.

Currently, the code runs fine as long as i use GetObject and Outlook is

open. CreateObject() fails with the (8007007e) error and if Outlook is

closed an error 429 (ActiveX can't create object).

My reference list contains the Microsoft Outlook 11 Object Library

C:\Program Files\Office2003\OFFICE11\msoutl.olb. I doubt if it makes a

difference but Outlook is not my default email reader.

Do you have any other suggestions?
 
First, use GetObject to see whether Outlook runs already. You need to catch

the error for the case that Outlook doesn't run. If it doesn't try this

instead of CreateObject:

Dim obj as Object

Set obj=New Outlook.Application

Does that work?

Best regards

Michael Bauer

Am Sat, 20 Feb 2010 08:37:56 -0800 schrieb Salad:


> Michael Bauer wrote:

>
> > Does the code run in Outlook? Then don't use any of the methods; there's
> > already an Application object, which you should use.
>

>> Both methods are only used if you want to access an application from
> > outside. For instance, from Outlook you could use CreateObject to start a
> > new instance of Excel, or use GetObject to access a running instance of
> > Excel.
> >

> Hi Michael, Thanks for your response.

> I was excited with your response when you mentioned the Application
> object but got crushed when you mentioned that GetObject/CreateObject
> were used from an external app. And that's the case...I am running it
> from Access 2003 and setting the object for Outlook 2003. I should have
> mentioned that in the original post.

> Currently, the code runs fine as long as i use GetObject and Outlook is
> open. CreateObject() fails with the (8007007e) error and if Outlook is
> closed an error 429 (ActiveX can't create object).

> My reference list contains the Microsoft Outlook 11 Object Library
> C:\Program Files\Office2003\OFFICE11\msoutl.olb. I doubt if it makes a
> difference but Outlook is not my default email reader.

> Do you have any other suggestions?
 
Michael Bauer wrote:

> First, use GetObject to see whether Outlook runs already. You need to catch
> the error for the case that Outlook doesn't run. If it doesn't try this
> instead of CreateObject:

> Dim obj as Object
> Set obj=New Outlook.Application

> Does that work?
>


Hi Michael:

I ran the following code:

Sub TestIt()

Dim obj As Object

Set obj = New Outlook.Application

Set obj = Nothing

End Sub

I am running it from Access. I get an "Automation Error: The specified

module could not be found."

My references are

VBA

Access Object Library

DAO 3.6 Object Library

Outlook Object Library

Ole Automation

ActiveX Data Object 2.1

I deesn't seem so matter if I shuffle the order of the last 3, still get

the above error. Any other suggestions? It appears to be one of those

weird, hard to determine ones.
 
Is anything highlighted when the error occurs?

Best regards

Michael Bauer

Am Mon, 22 Feb 2010 08:08:04 -0800 schrieb Salad:


> Michael Bauer wrote:
>

>> First, use GetObject to see whether Outlook runs already. You need to


catch
> > the error for the case that Outlook doesn't run. If it doesn't try this
> > instead of CreateObject:
>

>> Dim obj as Object
> > Set obj=New Outlook.Application
>

>> Does that work?
> >


> Hi Michael:

> I ran the following code:
> Sub TestIt()
> Dim obj As Object
> Set obj = New Outlook.Application
> Set obj = Nothing
> End Sub

> I am running it from Access. I get an "Automation Error: The specified
> module could not be found."

> My references are
> VBA
> Access Object Library
> DAO 3.6 Object Library
> Outlook Object Library
> Ole Automation
> ActiveX Data Object 2.1

> I deesn't seem so matter if I shuffle the order of the last 3, still get
> the above error. Any other suggestions? It appears to be one of those
> weird, hard to determine ones.
 
Michael Bauer wrote:



> Is anything highlighted when the error occurs?
>


Yes, if I enter Debug mode, the line

Set obj = New Outlook.Application

is highlighted in the code below.

Sub TestIt1()

Dim obj As Object

Set obj = New Outlook.Application

Set obj = Nothing

End Sub

Running from Outlook, the following fails on CreateObject. From Access,

both fail unless Outlook is open.

Sub test()

Dim olApp As Outlook.Application

'Set olApp = CreateObject("Outlook.Application") 'fails

Set olApp = GetObject(, "Outlook.Application") 'outlook open, OK

Set olApp = Nothing

MsgBox "Done"

End Sub

Who knows. Maybe I hosed Outlook playing around with it. As long as

Outlook is open all is well. If not, CreateObject and GetObject fail.

I can live with that, I simply have to adjust.
 
Years ago I've read that a so called script blocker could prevent you from

launching Outlook by code. I don't know any details. If that's not the case,

I've no clue what's going on.

If you can't find the solution, you could do this: Try GetObject, if it

throws an error, you know that OL isn't running. Display a MsgBox then to

ask the user to start Outlook.

Best regards

Michael Bauer

Am Tue, 23 Feb 2010 11:17:14 -0800 schrieb Salad:


> Michael Bauer wrote:
>
>

>> Is anything highlighted when the error occurs?
> >

> Yes, if I enter Debug mode, the line
> Set obj = New Outlook.Application
> is highlighted in the code below.

> Sub TestIt1()
> Dim obj As Object
> Set obj = New Outlook.Application
> Set obj = Nothing
> End Sub

> Running from Outlook, the following fails on CreateObject. From Access,
> both fail unless Outlook is open.
> Sub test()
> Dim olApp As Outlook.Application
> 'Set olApp = CreateObject("Outlook.Application") 'fails
> Set olApp = GetObject(, "Outlook.Application") 'outlook open, OK
> Set olApp = Nothing
> MsgBox "Done"
> End Sub

> Who knows. Maybe I hosed Outlook playing around with it. As long as
> Outlook is open all is well. If not, CreateObject and GetObject fail.
> I can live with that, I simply have to adjust.
 
Michael Bauer wrote:



> Years ago I've read that a so called script blocker could prevent you from
> launching Outlook by code. I don't know any details. If that's not the case,
> I've no clue what's going on.


Yeah, it's a weird issue.


> If you can't find the solution, you could do this: Try GetObject, if it
> throws an error, you know that OL isn't running. Display a MsgBox then to
> ask the user to start Outlook.
>


That's what I do now. Thanks for your input.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J GetObject - Outlook/Excel 2007 Outlook VBA and Custom Forms 14
G Question marks in messages Using Outlook 2
e_a_g_l_e_p_i Question about calendar Using Outlook 5
e_a_g_l_e_p_i Question about installing my Gmail account on my iPhone but still getting messages downloaded to my desktop Outlook. Using Outlook 3
e_a_g_l_e_p_i Question about reinstalling Outlook 2021 Using Outlook 5
e_a_g_l_e_p_i question about 2-Step Verification with my gmail Using Outlook 0
D Question on removing an alias Using Outlook 1
O Newbie question: how to sync two Outlook -Exchange and IMAP- calendars? Using Outlook 4
D a general question re how backup programs handle pst files ... I have no problems, just curious Using Outlook 1
e_a_g_l_e_p_i A few question before I decide to switch to Pop from imap Using Outlook 9
D.Moore SendAndReceive question Outlook VBA and Custom Forms 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
N Question Using Outlook 8
D Shared Mailbox question Exchange Server Administration 1
CWM030 Another Quarantine question Exchange Server Administration 0
E Outlook 2010 Can somebody tell me , the question associated with OST format Using Outlook 1
CWM030 A quick question for Diane about Exchange Exchange Server Administration 2
CWM030 Email Catagorties question Using Outlook 1
MahdeeyaAbdulla Friend's outlook question Using Outlook 1
e_a_g_l_e_p_i Question about address book in Outlook 2010 Using Outlook 9
M Question about nested distribution lists Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i A question about installing office 2013 Pro and using my .pst from office 2010 Using Outlook 12
rerun101 Question about message options Outlook VBA and Custom Forms 4
M Question: Is there a rule that will save email in Windows Explorer Outlook VBA and Custom Forms 3
M Question on address book Using Outlook 1
e_a_g_l_e_p_i question about saving my .pst so I can import it to my Outlook after I build a new system Using Outlook 10
V Question on pop email Using Outlook 2
D a general question regarding data files Using Outlook 3
R Outlook 2007 - Email Question - POP3 to IMAP Outlook VBA and Custom Forms 11
D Advanced Search Question Using Outlook 1
adaminaus Quick question if i may Using Outlook 4
T Business Projects question BCM (Business Contact Manager) 0
V question about personal and shared calendars Exchange Server Administration 1
A Basic BCM question about sync to Outlook 2013 BCM (Business Contact Manager) 1
Jeff Rott Diane Question on "Use in a Run a Script Rule" Outlook VBA and Custom Forms 1
C Custom Forms: Question about retaining form information throughout the entire conversation Outlook VBA and Custom Forms 2
D OST question Exchange Server Administration 5
Mr Mayor Another recurring meeting question Using Outlook 1
V iCloud question Using Outlook 3
J "Specific word in body" question Using Outlook 1
A Newb-ish question Using Outlook 2
A The hardest VBA/Outlook question yet Using Outlook 1
S DAG question Exchange Server Administration 0
P Outlook File Extension Question Using Outlook 3
J Outlook 2010 Calendaring Question Using Outlook 0
K Syncing outlook with iCloud question Using Outlook 5
T Outlook Prf/Automation question Using Outlook 2
T Settings question Using Outlook 6
D Question re: Grouping by Due Date vs. Sorting by Due Date Using Outlook 1
IGWright Outlook 2013 .pst Question Using Outlook 10

Similar threads

Back
Top