Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2011, 03:53 AM
vadius vadius is offline Outlook : Delete an existing filtering rule using VBA Windows XP Outlook : Delete an existing filtering rule using VBA Office 2007
Novice
Outlook : Delete an existing filtering rule using VBA
 
Join Date: Aug 2011
Posts: 1
vadius is on a distinguished road
Default Outlook : Delete an existing filtering rule using VBA

Hi all,



I created a macro to add a filtering rule in Outlook 2007.
Each day, this rule must be updated. Do you know how I can specifiy in the beginning of my macro to look for the existing rule, if found, delete it and then create the updated rule. Like a daily update of the rule if you prefer...

Thanks

Code:
Sub CreateRule()


    Dim colRules As Outlook.Rules
    Dim oRule As Outlook.Rule
    Dim colRuleActions As Outlook.RuleActions
    Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction
    Dim oFromCondition As Outlook.ToOrFromRuleCondition
    Dim oExceptSubject As Outlook.TextRuleCondition
    Dim oInbox As Outlook.Folder
    Dim oMoveTarget As Outlook.Folder

    'Specify target folder for rule move action
    Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
    'Assume that target folder already exists
    Set oMoveTarget = oInbox.Folders("Test")
    
    'Get Rules from Session.DefaultStore object
    Set colRules = Application.Session.DefaultStore.GetRules()
    
    'Create the rule by adding a Receive Rule to Rules collection
    Set oRule = colRules.Create("Test's rule", olRuleReceive)

    'Specify the action in a MoveOrCopyRuleAction object
    'Action is to move the message to the target folder
    Set oMoveRuleAction = oRule.Actions.MoveToFolder
    With oMoveRuleAction
        .Enabled = True
        .Folder = oMoveTarget
    End With

    'Specify the exception condition for the subject in a TextRuleCondition object
    'Exception condition is if the subject contains "fun" or "chat"
    Set oConditionSubject = oRule.Conditions.Subject
    With oConditionSubject
        .Enabled = True
        .Text = Array("bla", "gla")
    End With

    'Update the server and display progress dialog
    colRules.Save
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2010 and modify font on existing e-mail snowens Outlook 1 04-06-2011 01:57 PM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
How do I set up a custom rule in Outlook 2002 mastermind Outlook 0 03-11-2010 11:03 PM
Having trouble with keywords in Outlook Rule mfarring Outlook 0 02-03-2010 08:17 AM
Outlook reminders for non-existing events RDeBord Outlook 2 01-21-2006 07:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft