Outlook object stopped working

M

muyBN

RunI have a Word document that I attach to an Outlook message with VBA. As
of yesterday, it all of a sudden quit working after about two months of
working just fine. I've closed and re-opened Word and Outlook, restarted the
computer, everything I could think of, but still get this error:

Run-time error '429':

Active-X component can't create object

Any ideas on how to resolve this, and why it would go inoperable from one
day to the next?
 
M

muyBN

Actually, I solved the 491 error, but now I'm getting this one:

Run-time error '91':

Object variable or With block variable not set

Following is the line where the error occurs; after that, I'll write the
complete section of code.

Set objItem = objOutlookApp.CreateItem(olMailItem)



On Error Resume Next
Set objOutlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If Err <> 0 Then
Set objOutlookApp = CreateObject("Outlook.Application")
blnStarted = True
End If
Set objItem = objOutlookApp.CreateItem(olMailItem)
 
J

Jezebel

The problem is that you are failing to instantiate objOutlookApp. The
mistake in your code is here
On Error GoTo 0
If Err <> 0 Then

All 'On error' statements clear the error object, so Err will always be zero
at this point. As you have it, the code will work if Outlook is already
running, but not otherwise. A simple fix is to use

On Error Resume Next
Set objOutlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlookApp is nothing then
...
 
M

muyBN

That was the trick. Thanks.
--
Bryan


Jezebel said:
The problem is that you are failing to instantiate objOutlookApp. The
mistake in your code is here


All 'On error' statements clear the error object, so Err will always be zero
at this point. As you have it, the code will work if Outlook is already
running, but not otherwise. A simple fix is to use

On Error Resume Next
Set objOutlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlookApp is nothing then
...
 
M

muyBN

Well, durn, it worked once then gave an error again (something like "module
couldn't be created"); now I just tried it again so I could get the exact
error code, then it worked! Does anyone have ideas on why it would work once
then not the next time? Here's the code:

On Error Resume Next
Set objOutlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlookApp Is Nothing Then
Set objOutlookApp = CreateObject("Outlook.Application")
blnStarted = True
End If
 
R

Russ

muyBN,

I'm new to invoking another app with code, but it might be that you need to
set objOutlookApp = Nothing to release it from memory when your done with it
before trying to create or set it again.
 

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