Wilder1626
asked on
Custom macro rule in Outlook 2007
Hello all,
I would like to know if it is possible to create a custom macro rule that if specific words appear in the sender name, the object, the body and attachment, to automatically deleted the email.
Please let me know.
Thanks for your help.
I would like to know if it is possible to create a custom macro rule that if specific words appear in the sender name, the object, the body and attachment, to automatically deleted the email.
Please let me know.
Thanks for your help.
ASKER
Great, here is what i need.
I need to be able to put a list of all the specific words that macro will filter on all these email fields:
.From
.Subject
.Body
.Attachments.Name
Ex: Casino, Gambler ..........
So if one of these words are in one of these fields, it will automatically deleted the email.
I need to be able to put a list of all the specific words that macro will filter on all these email fields:
.From
.Subject
.Body
.Attachments.Name
Ex: Casino, Gambler ..........
So if one of these words are in one of these fields, it will automatically deleted the email.
Are you ok with creating a rule on all incoming mails that calls a script?
Chris
Chris
ASKER
I no how to create regular rules but not that are related with a macro.
I was already using the outlook rule that was deleting words in the .Subject.
But if i can manage all the fields at once, it would be so good.
I was already using the outlook rule that was deleting words in the .Subject.
But if i can manage all the fields at once, it would be so good.
If so then add the following script to a normal module and call it from the rule ... i.e. Q_26883221
Chris
Chris
Sub Q_26883221(mai As MailItem)
Dim strFind As Variant
Dim blnNoGood As Boolean
Dim att As Attachment
For Each strFind In Array("Casino", "Gambler")
If InStr(1, mai.SenderName, strFind, vbTextCompare) > 0 Then
blnNoGood = True
Exit For
ElseIf InStr(1, mai.Subject, strFind, vbTextCompare) > 0 Then
blnNoGood = True
Exit For
ElseIf InStr(1, mai.body, strFind, vbTextCompare) > 0 Then
blnNoGood = True
Exit For
Else
For Each att In mai.Attachments
If InStr(1, att.name, strFind, vbTextCompare) > 0 Then
blnNoGood = True
Exit For
End If
Next
If blnNoGood Then Exit For
End If
Next
If blnNoGood Then mai.Delete
End Sub
ASKER
also, in that regular rule i have, i have about 70 words.
So it is very long to enter one by one in the rule.
It would be easier with a custom macro to also put the word list.
So it is very long to enter one by one in the rule.
It would be easier with a custom macro to also put the word list.
When creating your normal rule select all messages and then in actions instead of looking at the subject scroll down the actions box a bit further ... you will see run a script select that option instead and double click the hyperlink and the sub you added above should be visible.
Chris
Chris
Note the line:
For Each strFind In Array("Casino", "Gambler")
Keep adding your words here i.e. "Casino", "Gambler", "another", "fifty", "Words")
Chris
For Each strFind In Array("Casino", "Gambler")
Keep adding your words here i.e. "Casino", "Gambler", "another", "fifty", "Words")
Chris
ASKER
ok, i will try it now.
I will let you know the result.
Thanks
I will let you know the result.
Thanks
ASKER
wow this is working
Small question, what do i need to do if instead of deleting it, i want the macro to send it into the unwanted folder?
i guess i would change this: mai.Delete
Small question, what do i need to do if instead of deleting it, i want the macro to send it into the unwanted folder?
i guess i would change this: mai.Delete
Indeed and depending on where the folder unwanted is located ... can you advise it's path
Chris
Chris
ASKER
yes, it is in : \\Dossiers personnels
Folder name: Courrier indésirable
Folder name: Courrier indésirable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wow, one last question.
Can it go under a sub folder:\\Dossiers personnels\Courrier indésirable
Folder name: Test email
Can it go under a sub folder:\\Dossiers personnels\Courrier indésirable
Folder name: Test email
If I understand:
mai.Move Application.Session.folder s("Courrie r indésirable")
becomes
mai.Move Application.Session.folder s("Courrie r indésirable").folders("Tes t email")
But that folder needs to exist already.
Chris
mai.Move Application.Session.folder
becomes
mai.Move Application.Session.folder
But that folder needs to exist already.
Chris
ASKER
i have created the sun folder "Test email" but it keeps going in the "Courrier indésirable" folder
Is test email a sub folder of Courrier indésirable or t the same level
Chris
Chris
If it is a sub folder then can you supply your code as it is at the moment
Chris
Chris
ASKER
it is really a sub folder
Courrier indésirable
- Test email
Deleted items
Courrier indésirable
- Test email
Deleted items
ASKER
i see that even if a remove this part of the code:
it still always go in .folders("Courrier indésirable")
I don't understand why.
mai.Move Application.Session.folders("Courrier indésirable")
it still always go in .folders("Courrier indésirable")
I don't understand why.
ASKER
Thanks for your help.
I will take this one.
I will take this one.
I guess you have a rule that is doing that move over and above the one with the call to the script?
Chris
Chris
If specific word(s) appear in the Sender name or the body or any attachments, (name or contents?) then delete the mail?
Chris