ActiveX component can't create an object

S

Shu

Hello,
I registered an Outlook 9.0 object for Reference in Excel
2000, try to send an email, but still got the error
message:
"ActiveX component can't create an object"

the code I used is:
Public Sub SendMes(DisplayMsg As Boolean, Optional
AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
'This is the error message comes from
Set objOutlook = CreateObject("Outlook.Application")
'Set objOutlook = New Outlook.Application
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add
("(e-mail address removed)")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("Michael
Suyama")
'objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("Andrew
Fuller")
' objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the
message.
.Subject = "This is an Automation test with
Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf
& vbCrLf
'.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
' Set objOutlookAttach = .Attachments.Add
(AttachmentPath)
'End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

'Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub

I had used this code in Word 97, the difference is it is
based on Outlook 8.0 object. It worked well.

I really apreciate if someone can tell me what's wrong.

Regards
Shu
 
D

Dave Peterson

I don't automate outlook, so this might not work for you.

I'd drop the reference to Outlook completely.

And instead of declaring all your object variables by their correct type, just
declare them as objects:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

becomes:

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object

And maybe a check to see if Outlook is really installed:

set objOutlook = nothing
on error resume next
Set objOutlook = CreateObject("Outlook.Application")
on error goto 0

if objoutlook is nothing then
msgbox "Outlook couldn't be started"
exit sub
end if
....
 

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