ActiveX component can't create object

G

Guest

I'm trying to send a message in Outlook that originates from a Word file but
I get the message that "ActiveX component can't create object" on the first
line of code from the following macro. (I am running Office 2003 and have the
most recent Outlook, Office and ActiveX object library references checked.)
Any suggestions would be greatly appreciated as I am using this as a job
search tool.

Sub SendFile()
…

Dim OLI As Outlook.Inspector, strAccountBtnName As String, intLoc As
Integer, blnStarted As Boolean
Dim CBs As Office.CommandBars, CBP As Office.CommandBarPopup, MC As
Office.CommandBarControl
Const ID_ACCOUNTS = 31224
Dim objOutlookApp As Outlook.Application, objItem As Outlook.MailItem

…

Set objOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlookApp = CreateObject("Outlook.Application")
blnStarted = True
End If
Set objItem = objOutlookApp.CreateItem(olMailItem)
'select account to send from (adapted from
http://www.outlookcode.com/codedetail.aspx?id=889)
Set OLI = objItem.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, ID_ACCOUNTS)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
'' If strAccountBtnName = AccountName Then
'' MC.Execute
'' Set_Account = AccountName
'' GoTo Exit_Function
'' End If
Next
End If
End If

…

Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing

End Sub
 
G

Guest

This was actually running once upon a time without errors, but if I remember
correctly, I had something at the very top of the module. Then I had a
problem with my Word normal.dot and had to reconstruct everything and left
off the code at the beginning of the module. Thought I'd add that scenario in
case it had any bearing on my problem.
 
S

Sue Mosher [MVP-Outlook]

If you get an error from code statements like these:

Dim ol as New Outlook.Application

Set ol = CreateObject("Outlook.Application")

the cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. The solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Add an On Error Resume Next statement. GetObject will return Nothing if Outlook isn't already running. That's perfectly normal.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


muyBN said:
Thanks, but after I turned off the virus protection, the same error occurred.
 
G

Guest

"Danger, Will Robinson, danger!" Disregard the above brain-frozen remark.
What I was thinking of had to do with a "Type" statement at the beginning of
a module, which had nothing to do with this subject.
 
G

Guest

I don't quite understand what you're suggesting. I need the GetObject code in
order to get the results that I want and "On Error Resume Next" will not fix
the problem rather will skip over it if it throws an error. I need to figure
out why ActiveX won't create the object.
 
S

Sue Mosher [MVP-Outlook]

Exactly. If you get an error from GetObject, it means that Outlook isn't running. So you need to move on to CreateObject.

Did you try it?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


muyBN said:
I don't quite understand what you're suggesting. I need the GetObject code in
order to get the results that I want and "On Error Resume Next" will not fix
the problem rather will skip over it if it throws an error. I need to figure
out why ActiveX won't create the object.
 
G

Guest

Got it! Now I understand. I put "Resume Next" before the GetObject and "GoTo
0" after. Now it works! Before this, I was wondering why the suggested code
included both a GetObject and a CreateObject command. Now I know. Thank you
very much.
 
S

Spawn666948

From what I've noticed, the runtime errror "ActiveX component can't create
object" might mean you have a GetObject statement but the object is not
loaded. Eg; Outlook isn't running.
 
S

Sue Mosher [MVP-Outlook]

Add an On Error Resume Next statement in the declarations section of your procedure, so that if GetObject() can't return it, the code can execute CreateObject.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Thanks, I followed your suggestion and it worked, but only when Outlook is
already open. Is that the way it should go? I thought that CreateObject was
supposed to open Outlook so the object could be created.
 
S

Sue Mosher [MVP-Outlook]

It won't if an anti-virus program is blocking Outlook scripting.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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