Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   ActiveX component can't create object (http://www.outlookbanter.com/outlook-vba/21807-activex-component-cant-create-object.html)

muyBN July 26th 06 12:05 AM

ActiveX component can't create object
 
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

--
Thanks from Bryan

muyBN July 26th 06 12:11 AM

ActiveX component can't create object
 
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.
--
Bryan


"muyBN" wrote:

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

--
Thanks from Bryan


Sue Mosher [MVP-Outlook] July 26th 06 12:39 AM

ActiveX component can't create object
 
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan


muyBN July 26th 06 08:34 AM

ActiveX component can't create object
 
Thanks, but after I turned off the virus protection, the same error occurred.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan



Sue Mosher [MVP-Outlook] July 26th 06 01:14 PM

ActiveX component can't create object
 
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
Thanks, but after I turned off the virus protection, the same error occurred.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan



muyBN July 26th 06 05:15 PM

ActiveX component can't create object
 
"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.
--
Bryan


"muyBN" wrote:

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.
--
Bryan


"muyBN" wrote:

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

--
Thanks from Bryan


muyBN July 26th 06 08:45 PM

ActiveX component can't create object
 
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
Thanks, but after I turned off the virus protection, the same error occurred.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan



Sue Mosher [MVP-Outlook] July 26th 06 09:19 PM

ActiveX component can't create object
 
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
Thanks, but after I turned off the virus protection, the same error occurred.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan



muyBN July 27th 06 01:33 AM

ActiveX component can't create object
 
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
Thanks, but after I turned off the virus protection, the same error occurred.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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

--
Thanks from Bryan




Spawn666948 July 29th 06 08:33 PM

ActiveX component can't create object
 
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.

--

"muyBN" wrote in message
...
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

--
Thanks from Bryan




Sue Mosher [MVP-Outlook] July 29th 06 10:22 PM

ActiveX component can't create object
 
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message
...
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



muyBN August 31st 06 11:45 PM

ActiveX component can't create object
 
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message
...
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




Sue Mosher [MVP-Outlook] September 1st 06 12:31 AM

ActiveX component can't create object
 
It won't if an anti-virus program is blocking Outlook scripting.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"muyBN" wrote in message ...
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.
--
Bryan


"Sue Mosher [MVP-Outlook]" wrote:

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.



"muyBN" wrote in message
...
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





All times are GMT +1. The time now is 06:15 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-2006 OutlookBanter.com