'How can a run a script rule be reset after it stops working?
I cobbled together a script and rule to save incoming emails as .txt files on our server.
It works for about a day or two, but then stops working until I delete and remake the rule.
It seems if the server times out, the rule throws an error and will not reset.
How can the rule/script be reset after an error?
Sub AutoSaveAsTxt(Item As Outlook.MailItem)
On Error Resume Next
Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim rName As String
Dim subName As String
Dim fName As String
Dim enviro As String
If Item.Class = olMail Then
Set oMail = Item
End If
dtDate = oMail.SentOn
Dim intSeconds As Integer
intSeconds = Second(dtDate)
If intSeconds > 29 Then
dtDate = DateAdd("s", 60 - intSeconds, dtDate)
End If
sName = oMail.SenderName
If sName = "" Then
sName = "[No Sender Name]"
End If
rName = oMail.Recipients(1)
If rName = "" Then
rName = "[No Recipient Name]"
End If
subName = oMail.Subject
If subName = "" Then
subName = "[No Subject Line]"
End If
fName = Format(dtDate, "yymmdd.hhmm", vbUseSystemDayOfWeek, _
vbUseSystem) & "." & sName & "." & rName & "." & subName & ".txt"
ReplaceCharsForFileName fName, ""
'Don't forget to Change user name and create the folder prior to use'
sPath = enviro & "\\server1\d-drive\Saved Emails\Johnny Emails\"
Debug.Print sPath & fName
oMail.SaveAs sPath & fName, olTXT
Set oMail = Nothing
End Sub
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
sName = Replace(sName, "'", sChr)
sName = Replace(sName, "*", sChr)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
Rule:
Apply this rule after the message arrives
run Project1.AutoSaveAsTxt
except with 'mycase' or 'azbar' in the sender's address
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|