Trying To Create New MS Outlook Rule w/Visual Basic

  • Thread starter Thread starter Heinlein
  • Start date Start date
H

Heinlein

I've tried an Outlook group, but have received no replies.
I don't know Visual Basic, outside of a few examples I found through
Google.
I'm trying to write a rule to compensate for laziness caused by
program changes. Used to be, case numbers for family law cases where I
work were written as follows: 12-DR-012345. Now, you can get away
with 12DR12345, and the file management program accepts it.
I had a filter in MS Outlook so that all messages with -DR- in it got
moved to a subfolder in my email, with the name Family Law. Now that
people can be lazy, that rule can't work.
I tried following guidelines at this location:
http://www.stackoverflow.com/questions/3865500/regular-expression-rul...
mainly those in the "first page" area. For a while my rule would pop
up when a message came in with the new format, so I assume the rule
"saw it". Unfortunately, I can't move the message to my Family Law
subfolder.
This is what my routine looks like:
Sub CaseNumberFilter(Message As Outlook.MailItem)
Dim MatchesSubject, MatchesBody
Dim RegEx As New RegExp
'e.g. 1000-10'
RegEx.Pattern = "([0-9]{2}DR[0-9]{6})"
'Check for pattern in subject and body'
If (RegEx.Test(Message.Subject) Or RegEx.Test(Message.Body)) Then
Set MatchesSubject = RegEx.Execute(Message.Subject)
Set MatchesBody = RegEx.Execute(Message.Body)
If Not (MatchesSubject Is Nothing And MatchesBody Is Nothing)
Then
'Assign "Job Number" category'
Message.Categories = "Job Number"
Message.Save
End If
End If
End Sub
No idea what to do to make it work. Appreciate any help. Now that
programming lets people "be lazy", I'll need three versions of this
macro/routine. The number I'm filtering for could resemble anything
from:
1DR1 to 12DR012345.
Thanks in advance.
Oh, my shop used MS Office 2007.
 
I had a look at this info at microsoft.com:
http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx

However, it looks like you can do either a character to character, or a field to field, comparison.
Not sure how I'd compare a string to any position in an MS Outlook message's subject or body. Would I replace the Regex part of the subroutine with a Like compare?
 
(e-mail address removed) pretended :
I had a look at this info at microsoft.com:
http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx

However, it looks like you can do either a character to character, or a
field to field, comparison. Not sure how I'd compare a string to any
position in an MS Outlook message's subject or body. Would I replace the
Regex part of the subroutine with a Like compare?

Yes!
Though I do not use RegEx, there are people here who have mastered it.
Hopefully one of them will chip in if you insist on using RegEx instead
of Like().
--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Here's my attempt. Isn't working. Appreciate your help to debug it. I don't get any error messages, it just doesn't work (I sent myself a message from my cell, with 01dr1234 in the body. Just went to Inbox, vs going to subfolder Family Pleadings.

Sub CaseNumberFilter(Message As Outlook.MailItem)
Dim MatchesSubject, MatchesBody
Dim testCheck As Boolean

''e.g. 10dr123456''
testCheck = "(Message.Subject)" Or "(Message.Body)" Like "([0-9]{1-2}dr[0-9]{1-6})"
''Check for pattern in subject and body''
MoveToFolder ("Family Pleadings") ''End Sub''
Message.Save
End If
End If
End Sub
 
Back
Top