Hello,
I have a script that i need to execute every time I receive an email in my outlook account. I have added the script in this outlook session. The script runs well manually but when i am trying to tie it up with a rule "run a Script" I cannot see anything in the Script window it appears blank. Please help me know where is the problem. The code I am trying to use is as follows:
If there is problem with this script please help me with the modified Script. I also tried to use Newevent as application and Newmail but it is also not working.
I have a script that i need to execute every time I receive an email in my outlook account. I have added the script in this outlook session. The script runs well manually but when i am trying to tie it up with a rule "run a Script" I cannot see anything in the Script window it appears blank. Please help me know where is the problem. The code I am trying to use is as follows:
Code:
Option Explicit
Public Sub SaveMessageAsMsg()
Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
For Each objItem In ActiveExplorer.Selection
Set oMail = objItem
sName = oMail.Subject
ReplaceCharsForFileName sName, "_"
dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
sPath = enviro & "\Documents\"
Debug.Print sPath & sName
oMail.SaveAs sPath & sName, olMSG
Next
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, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
If there is problem with this script please help me with the modified Script. I also tried to use Newevent as application and Newmail but it is also not working.
Last edited by a moderator: