I get an error when I try to run this send an email with the following code.
PLEASE HELP. This was working perfectly them all of a sudden it stopped and I get this error. What is causing this error?
MESSAGE:
runtime error: -2147023170 '(800706be)'
Automation error The remote procedure call failed
Function Send_Outlook(Optional strTO As String = "myemail@domain.com", Optional strCC As String, Optional strBCC As String, Optional Subject As String = "Report (bla bla)", Optional Body As String = "Attached please find reports", Optional ByRef path1 As Variant)
'*********************************************************
' TURN ON CLICK_ YES
Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long
'Register a message to send
uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")
' Find ClickYes Window by classname
wnd = FindWindow("EXCLICKYES_WND", 0&)
' Send the message to Resume ClickYes
Res = SendMessage(wnd, uClickYes, 1, 0)
' ...
' Do some Actions
'**************************************
Dim dbName
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
If strTO = "" Then
strTO = "myemail@domain.com"
End If
With MailOutLook
.TO = strTO
.CC = strCC
.BCC = strBCC
.Subject = Subject
.Body = Body
End With
'*****************************************************************
Dim objattach As Variant
If Testarray(path1) Then
For Each objattach In path1
If Not IsEmpty(objattach) And Not IsNull(objattach) Then
objattach = Right(objattach, Len(objattach) - 1)
'needs to check is file exists******************
MailOutLook.attachments.Add objattach
End If
Next
End If
MailOutLook.Send
'Record message as sent in tbl_email_log
Call email_log(strTO, strCC, strBCC, Subject, Body, "Outlook", path1)
'Timer function********************************************
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 5 ' Set duration.
Start = timer ' Set start time.
Do While timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time
'*********************************************************
'appOutLook.Quit
Set MailOutLook = Nothing
Set appOutLook = Nothing
' ...
' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)
End Function
PLEASE HELP. This was working perfectly them all of a sudden it stopped and I get this error. What is causing this error?
MESSAGE:
runtime error: -2147023170 '(800706be)'
Automation error The remote procedure call failed
Function Send_Outlook(Optional strTO As String = "myemail@domain.com", Optional strCC As String, Optional strBCC As String, Optional Subject As String = "Report (bla bla)", Optional Body As String = "Attached please find reports", Optional ByRef path1 As Variant)
'*********************************************************
' TURN ON CLICK_ YES
Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long
'Register a message to send
uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")
' Find ClickYes Window by classname
wnd = FindWindow("EXCLICKYES_WND", 0&)
' Send the message to Resume ClickYes
Res = SendMessage(wnd, uClickYes, 1, 0)
' ...
' Do some Actions
'**************************************
Dim dbName
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
If strTO = "" Then
strTO = "myemail@domain.com"
End If
With MailOutLook
.TO = strTO
.CC = strCC
.BCC = strBCC
.Subject = Subject
.Body = Body
End With
'*****************************************************************
Dim objattach As Variant
If Testarray(path1) Then
For Each objattach In path1
If Not IsEmpty(objattach) And Not IsNull(objattach) Then
objattach = Right(objattach, Len(objattach) - 1)
'needs to check is file exists******************
MailOutLook.attachments.Add objattach
End If
Next
End If
MailOutLook.Send
'Record message as sent in tbl_email_log
Call email_log(strTO, strCC, strBCC, Subject, Body, "Outlook", path1)
'Timer function********************************************
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 5 ' Set duration.
Start = timer ' Set start time.
Do While timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time
'*********************************************************
'appOutLook.Quit
Set MailOutLook = Nothing
Set appOutLook = Nothing
' ...
' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)
End Function