I am using the following code but when i run it produces the following error.
Run-time error '429':
ActiveX component can't create object.
then on debug it highlights the line
Set objOutlook = CreateObject("Outlook.Application")
I have searched online and already tried a suggestion to ensure that mictosoft outlook 14.0 object library is selected in the VBA references.
Anyone have an idea?
Run-time error '429':
ActiveX component can't create object.
then on debug it highlights the line
Set objOutlook = CreateObject("Outlook.Application")
I have searched online and already tried a suggestion to ensure that mictosoft outlook 14.0 object library is selected in the VBA references.
Anyone have an idea?
Code:
Dim objOutlook As Object
Dim objMailItem As Object
Const olMailItem As Integer = 0
Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(olMailItem)
'set the object from template
Set objMailItem = objOutlook.CreateItemFromTemplate("C:\FastFile\System 3.0\3.0\BLANKTEMP.oft")
strEmail = "test@testing.com"
strSubject = "Test"
strBody = "Test the Outlook Object"
strPathAttach = "C:\FastFile\System 3.0\sampleatt.pdf"
On Error GoTo err_Error_handler
'set receipient
objMailItem.To = strEmail
'set subject
objMailItem.Subject = strSubject
'set body content
objMailItem.Body = strBody
'Check path and file, then set Attachment
If Len(Dir(strPathAttach)) Then
With objMailItem.Attachments
'use parenthisis around the path
.Add (strPathAttach)
End With
End If
'sending email
objMailItem.Send
Set objOutlook = Nothing
Set objMailItem = Nothing
exit_Error_handler:
On Error Resume Next
Set objOutlook = Nothing
Set objMailItem = Nothing
Exit Sub
err_Error_handler:
Select Case Err.Number
'trap error 287
Case 287
MsgBox "Canceled by user.", vbInformation
Case Else
MsgBox "Error " & Err.Number & " " & Err.Description
End Select
Resume exit_Error_handler