Log in

View Full Version : Search and Replace patterns of strings with a RULE with any new message received.



sev7en
05-04-2015, 06:38 AM
Good afternoon,
I created the script below to check in Outlook the incoming mail (it's to remark potential URL with spyware). That script works if I run it manually but I don't know how to change it as to make it working as a Rule. Can you kindly give me the details to make it as Rule?

I want to create a rule in Outlook to run that Script with any new incoming message.



Sub RemoveExpression()

Dim outApp As Object
Dim outInsp As Object
Dim outObj As Object
Dim strTextToReplace As String


Set outApp = GetObject(, "Outlook.Application")
Set outInsp = outApp.ActiveInspector
Set outObj = outInsp.CurrentItem

strTextToReplace = "/index.php"
strTextToReplace2 = "/default.php"
strTextToReplace3 = ".exe"
strTextToReplace4 = ".com"


outObj.Body = Replace(outObj.Body, strTextToReplace, "/index.p h p")
outObj.Body = Replace(outObj.Body, strTextToReplace2, "/default.p h p")
outObj.Body = Replace(outObj.Body, strTextToReplace3, ".e x e")
outObj.Body = Replace(outObj.Body, strTextToReplace4, ".c o m")


Set outObj = Nothing
Set outInsp = Nothing
Set outApp = Nothing


End Sub




Thanks for your support

skatonni
05-04-2015, 12:34 PM
Option Explicit

Sub RemoveExpression_V2(item As Object) ' <-- this is the format for a RunAScript rule

Dim strTextToReplace As String
Dim strTextToReplace2 As String
Dim strTextToReplace3 As String
Dim strTextToReplace4 As String

strTextToReplace = "/index.php"
strTextToReplace2 = "/default.php"
strTextToReplace3 = ".exe"
strTextToReplace4 = ".com"

' Refer to the single item passed, everywhere in the code
item.body = Replace(item.body, strTextToReplace, "/index.p h p")
item.body = Replace(item.body, strTextToReplace2, "/default.p h p")
item.body = Replace(item.body, strTextToReplace3, ".e x e")
item.body = Replace(item.body, strTextToReplace4, ".c o m")

End Sub

Private Sub test_RemoveExpression_V2()

' open a test item
Dim curritem As Object
Set curritem = ActiveInspector.currentItem
RemoveExpression_V2 curritem
Set curritem = Nothing

End Sub

sev7en
05-04-2015, 04:31 PM
Good morning,
thanks for your reply but maybe I was not clear: the macro I wrote above is not recognized as a Outlook Script and I am not able to run it is a Rule. What piece of code I have to add to use that macro as a Script for Outlook's rules?


With Regards,

skatonni
05-04-2015, 06:22 PM
To get the code to show up in the list available for RunAScript the first line has to in this format to pass a parameter which is item.

Sub RemoveExpression_V2(item As Mailitem)

I did not test with a rule so I originally inadvertently had item as Object.

http://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/

sev7en
05-04-2015, 08:34 PM
To get the code to show up in the list available for RunAScript the first line has to in this format to pass a parameter which is item.

Sub RemoveExpression_V2(item As Mailitem)
Good morning,
first of all thanks for your reply, I edited the code, now the script is recognized but when executed it stops due to the error below:

13298

how can I do?


Thank you,

sev7en
05-04-2015, 09:27 PM
Good morning,
just an updated, in that way the code is working but also if properly set to the Rule for check any received messages it doesn't start automatically. If instead I run it manually, it works...

13299

skatonni
05-05-2015, 03:35 AM
If the code does not run this implies the rule is not set correctly.

Post a screenshot of a test mail and I will try to recreate my own test mail.

sev7en
05-05-2015, 04:07 AM
If the code does not run this implies the rule is not set correctly.

Post a screenshot of a test mail and I will try to recreate my own test mail.
Good afternoon,
thanks for your kindness. It is not a problem about the email to just because when I run the script manually it works and make the related operation on the mail, it's a problem of the Outlook I guess.. I have the version 2013.