Complex Outlook rules - programatically?

  • Thread starter Thread starter outlook
  • Start date Start date
O

outlook

I'd like to put files that have (xxx) anywhere in the subject into the
folder named "xxx", regardless if they were received or sent by me.
xxx could be any 3 digit number, e.g. 237 or 450 or 007. Without
having to write 999 separate rules, is there perhaps a way to do this
programatically. Or is there perhaps a way programatically to write
the 999 rules? Thanks, JimPS I have OL2003
 
You could, in theory, do it as one rule with a "run a script" rule action. Such actions use not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code:


Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
MsgBox msg.SUbject

Set msg = Nothing
Set olNS = Nothing
End Sub

See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue, I don't understand VB enough to know what to do with this code.
Or how to edit it to accomplish what I am trying to do. Is there
perhaps a way to edit and manipulate the existing rules, so that I
could just build the 1000 rules faster than using the rules wizard
interface?
 
Outlook 2007 is the first version with native ability to create rules programmatically, and even it's a bit complicated. For earlier versions, you have to use CDO 1.21 and a separate Rule.dll COM component, and it's even more complex than doing it with Outlook 2007.

In any case, the approach I suggested could handle your requirements with just one rule, not 1000. As this statement shows:

MsgBox msg.Subject

you can get at the Subject and other properties of the message with code run from a rule that has a "run a script" action that points to the code procedure. If you need VBA basics, see http://www.outlookcode.com/d/vbabasics.htm.

If the subject has a structure to it, you can parse it with standard functions like Instr() to locate the number. If it has no structure, then the best approach would be to use regular expressions (a technique used by many anti-spam programs) to locate the three-digit pattern anywhere in the subject. Links to info on regular expressions are at http://www.outlookcode.com/d/vbscript.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top