Why Creating object failed even I set a reference to this object?

S

Shu

Hello,
I set a reference to an Outlook 9.0 object 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 any help.

Regards
Shu
 
F

Frank Kabel

Hi
just a guess without looking at your code: Have you set a reference to
Outlook (thats is the Outlook object) in your VBE Editor.
If not, goto 'Tools - Reference' and check Outlook (for me: Microsoft
Outlook 1.0 Object library)
 
G

Guest

Hi Frank,
I did set a reference to Outlook object.
I am using MS Office 2000. There is no default outlook
object in the reference dialog box. I browsed into the
particular file, find it, then check it.
The VBE has indicated the Outlook object is set up, but
whenever it executes the createobject line, The error
message pops up.
Any more idea? Thanks a lot.

Regards
Shu
 
D

Dave Peterson

See one more reply to your other post.
Hello,
I set a reference to an Outlook 9.0 object in Excel
2000, try to send an email, but still got the error
message:
"ActiveX component can't create an object"
<<snipped>>
 

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