处理Outlook规则中的错误

时间:2014-04-24 12:32:11

标签: outlook-vba

我有一个outlook规则,在触发时运行脚本。它可以在99%的时间内工作,但偶尔会出现这种操作失败"将显示一条消息,然后该规则将自动停用并显示为红色。

我不确定这是由于VBA代码中的问题还是其他原因,但我们将不胜感激。如果这是添加此问题的错误位置,请告诉我,但我找不到其他地方有道理的理由。

如果我们无法找到解决方案,是否有可能以某种方式自动再次启用规则,或者在发生此错误时发送通知电子邮件 - 因为这发生在"独立& #34; PC运行某些进程,并不是一直监控。

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 

1 个答案:

答案 0 :(得分:1)