A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

CreateObject(), GetObject() question



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 20th 10, 02:05 AM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default CreateObject(), GetObject() question

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?
Ads
  #2  
Old February 20th 10, 07:42 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default CreateObject(), GetObject() question



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 - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


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?

  #3  
Old February 20th 10, 04:37 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default CreateObject(), GetObject() question

Michael Bauer [MVP - Outlook] 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?


  #4  
Old February 22nd 10, 09:28 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default CreateObject(), GetObject() question



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 - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


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

Michael Bauer [MVP - Outlook] 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?

  #5  
Old February 22nd 10, 04:08 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default CreateObject(), GetObject() question

Michael Bauer [MVP - Outlook] 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.



  #6  
Old February 23rd 10, 08:31 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default CreateObject(), GetObject() question



Is anything highlighted when the error occurs?

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


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

Michael Bauer [MVP - Outlook] 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.

  #7  
Old February 23rd 10, 07:17 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default CreateObject(), GetObject() question

Michael Bauer [MVP - Outlook] 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.



  #8  
Old February 24th 10, 08:20 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default CreateObject(), GetObject() question



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 - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


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

Michael Bauer [MVP - Outlook] 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.

  #9  
Old February 24th 10, 06:05 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default CreateObject(), GetObject() question

Michael Bauer [MVP - Outlook] 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.
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetObject - Outlook/Excel 2007 JoeRob Outlook and VBA 14 January 22nd 10 12:36 AM
CreateObject Fails with Error 429 [email protected] Outlook and VBA 3 January 22nd 09 10:23 AM
Legacy applicaton with CreateObject not working in Outllook 2007 Howard Myers Outlook - General Queries 1 June 27th 08 08:01 AM
Error 429 CreateObject Alberto[_2_] Outlook and VBA 7 May 12th 08 05:29 PM
OLK2007 : The Oper Failed : Application.CreateObject("MAPI.Session Bill Billmire Outlook - Using Forms 3 January 7th 07 01:02 AM


All times are GMT +1. The time now is 07:51 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright 2004-2025 Outlook Banter.
The comments are property of their posters.