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