user2725402
user2725402

Reputation: 4629

Handling errors in Outlook Rule

I have an outlook rule which runs a script when triggered. It works 99% of the time, but occasionally a "this operation failed" message appears and then the rule is automatically deactivated and shown in red.

I'm not sure if this is due to a problem in the VBA code or something else.

If we can't find a solution, is it possible to somehow automatically have the rule enabled again, or to send out a notification email when this error occurs - since this happens on a "stand-alone" PC running certain processes, and is not monitored the whole time.

Public Sub Recon(itm As Outlook.MailItem)
Dim dt As String
dt = Format(CStr(Now), "yyyymmddhhmmss")
Dim Filepath1 As String
Filepath1 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Queued\Recon_Acct_" & dt & ".txt"
Filepath2 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Queued\Recon_SenderEmail_" & dt & ".txt"
Filepath3 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Queued\Recon_SenderName_" & dt & ".txt"
Const ForWriting = 2

strAccNumber = Trim(Mid(itm.Subject, InStrRev(itm.Subject, " "), Len(itm.Subject) - InStr(1, itm.Subject, " ")))
strSender = itm.Sender.GetExchangeUser().PrimarySmtpAddress
strSenderName = itm.Sender

'Update the Account Number File:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(Filepath1)
oFile.WriteLine "SET vAcct = '" & strAccNumber & "';"
oFile.Close
Set fso = Nothing
Set oFile = Nothing

'Update the Sender Email Address File:
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile(Filepath2)
oFile.WriteLine strSender
oFile.Close
Set fso = Nothing
Set oFile = Nothing

'Update the Sender Name File:
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile(Filepath3)
oFile.WriteLine strSenderName
oFile.Close
Set fso = Nothing
Set oFile = Nothing

End Sub 

Upvotes: 1

Views: 746

Answers (1)

niton
niton

Reputation: 9179

Rules are notoriously unreliable.

Try using NewMailEx or Item_Add

http://msdn.microsoft.com/en-us/library/office/bb147646(v=office.12).aspx

http://msdn.microsoft.com/en-us/library/office/ff869609.aspx

Upvotes: 1

Related Questions