Cuestom outlook rule using vba

M

mherber2

Hello all,

Im needing to create some custom rules to orginize my email for me.

I need to write a rule so that an email containning an specific word i
the subject, sent to a person in a specific address book, or from
person in a specific address book moved to a specific folder.

I know i have to use vba because the wiz wont allow for an or it wil
only use and. Can any one please help me with this
 
M

mherber2

i am using 2007 however there is not a built in rule to sort when
message is sent to someone in a specified address book

'Ken Slovak - [MVP - Outlook said:
;295305']What version of Outlook? If this is Outlook 2007 you can us
the new Rules
collection, if not then you must have a rule that calls into a VB
macro
formatted in a specific way.

See http://www.outlookcode.com/article.aspx?id=62 and look for the ru
a
script rule.




"mherber2" (e-mail address removed) wrote in message

Hello all,

Im needing to create some custom rules to orginize my email for me.

I need to write a rule so that an email containning an specific wor
in
the subject, sent to a person in a specific address book, or from a
person in a specific address book moved to a specific folder.

I know i have to use vba because the wiz wont allow for an or it will
only use and. Can any one please help me with this?
 
K

Ken Slovak - [MVP - Outlook]

It looks like there aren't any conditions that meet what you want in the
Rules collection, so a rule that runs a script is your best bet.
 
M

mherber2

thats not a problem can you assist me in writing the script?

'Ken Slovak - [MVP - Outlook said:
;295682']It looks like there aren't any conditions that meet what yo
want in the
Rules collection, so a rule that runs a script is your best bet.




"mherber2" (e-mail address removed) wrote in message

i am using 2007 however there is not a built in rule to sort when a
message is sent to someone in a specified address book
 
K

Ken Slovak - [MVP - Outlook]

Start coding it and post any problems or questions and someone will help.
 
M

mherber2

i have experiance in vba for excell and power point but i have no clu
where to begin here. i've been working on coding it but cannt ge
anywhere

'Ken Slovak - [MVP - Outlook said:
;295859']Start coding it and post any problems or questions and someon
will help.




"mherber2" (e-mail address removed) wrote in message

thats not a problem can you assist me in writing the script?
 
K

Ken Slovak - [MVP - Outlook]

Well, the rule calling the macro "script" is passed a Mailitem object for
the item. To check for Subject containing a specific word:

Sub myRuleCode(Item As Outlook.MailItem)
If InStr(1, Item.Subject, "foobar", vbTextCompare) > 0 Then
' it has the subject word "foobar" there

To check for the recipient being in a specific AddressBook you'd need to get
the Item.Recipients collection and iterate, checking each Recipient for
their email address and seeing if the Recipient.Type = olTo (if you only
want to check the To recipient or recipients).

The AddressBook would be retrieved from the AddressLists collection as an
AddressList object. You'd get its AddressEntries collection and iterate that
looking for an AddressEntry where the Address property was equal to the
Recipient.Address.

To check for the sender being in the AddressEntries collection you'd use the
Item.SenderEmailAddress property and compare that to each
AddressEntry.Address value in that AddressBook.

If you know the name of the AddressBook you want to work with you'd get it
like this:

Dim oList As Outlook.AddressList
Set oList =
Application.GetNameSpace("MAPI").AddressLists.Item("myAddressList")

That should get you going.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top