Monday, March 10, 2014

list outlook rules

i sure would like my outlook rules in a text document.

from here:
http://www.slipstick.com/outlook/rules/create-list-rules/

Sub ListRules()
 Dim colStores As Outlook.Stores
    Dim oFileSys As Object
    Dim oStore As Outlook.Store
    Dim oRoot As Outlook.Folder
    Dim oCondition As Outlook.RuleCondition
    Dim oCondfrom As Outlook.RuleCondition
    Dim oAction As Outlook.RuleAction
    Dim colRules As Object
    Dim oRule As Outlook.Rule
    Dim oInbox As Outlook.Folder
    Dim oMoveTarget As Outlook.Folder
    Dim sOutput As String
    Dim myVar As Variant

    'On Error Resume Next
    Set oFileSys = CreateObject("Scripting.FileSystemObject")

'Create a folder named Rules on your C drive or change the path to use an existing folder
    If oFileSys.FileExists("C:\Rules\OLfilterlist.txt") Then
        oFileSys.DeleteFile ("C:\Rules\OLfilterlist.txt")
    End If
    Open "C:\Rules\OLfilterlist.txt" For Output As #1

    Set colStores = Application.Session.Stores
    Set oStore = colStores(1)
        Set oRoot = oStore.GetRootFolder
        Set colRules = oStore.GetRules
        
For Each oRule In colRules
sOutput = (oRule.ExecutionOrder) & Chr(9) & "Rule Name:" & (oRule.Name) & vbCrLf


  For Each oCondition In oRule.Conditions
    If oCondition.Enabled = True Then
'From
 If oCondition.ConditionType = olConditionFrom Then
   sOutput = sOutput & Chr(9) & "From:" & (oRule.Conditions.From.Recipients(1)) & vbCrLf
 End If

'Words in the Subject
If oCondition.ConditionType = olConditionSubject Then

'use this format when the condition may contain multiple values
   sOutput = sOutput & Chr(9) & "Subject:"
      For Each myVar In oRule.Conditions.Subject.Text
        sOutput = sOutput & "'" & myVar & "' "
     Next
    sOutput = sOutput & vbCrLf
End If

If oCondition.ConditionType = olConditionBody Then
   sOutput = sOutput & Chr(9) & "Body:" & (oRule.Conditions.Body.Text) & vbCrLf
End If
               
If oCondition.ConditionType = olConditionMessageHeader Then
   sOutput = sOutput & Chr(9) & "Header:" & (oRule.Conditions.MessageHeader.Text) & vbCrLf
End If

If oCondition.ConditionType = olConditionBodyOrSubject Then
  sOutput = sOutput & Chr(9) & "Body Or Subject:"
     For Each myVar In oRule.Conditions.BodyOrSubject.Text
        sOutput = sOutput & "'" & myVar & "' "
     Next
     sOutput = sOutput & vbCrLf
End If

If oCondition.ConditionType = olConditionCategory Then
   sOutput = sOutput & Chr(9) & "Category:"
    For Each myVar In oRule.Conditions.Category.Categories
    sOutput = sOutput & "'" & myVar & "' "
    Next
  sOutput = sOutput & vbCrLf
End If

If oCondition.ConditionType = olConditionAccount Then
   sOutput = sOutput & Chr(9) & "Account:" & (oRule.Conditions.Account.Account) & vbCrLf
End If

If oCondition.ConditionType = olConditionAnyCategory Then
   sOutput = sOutput & Chr(9) & "AnyCategory:" & (oRule.Conditions.AnyCategory) & vbCrLf
End If

If oCondition.ConditionType = olConditionCc Then
   sOutput = sOutput & Chr(9) & "CC:" & (oRule.Conditions.CC.Enabled) & vbCrLf
End If


If oCondition.ConditionType = olConditionFlaggedForAction Then
   sOutput = sOutput & Chr(9) & "Flagged:" & (oRule.Enabled) & vbCrLf
End If


If oCondition.ConditionType = olConditionHasAttachment Then
   sOutput = sOutput & Chr(9) & "Attachment:" & (oRule.Conditions.HasAttachment.Enabled) & vbCrLf
End If


If oCondition.ConditionType = olConditionSenderAddress Then
   sOutput = sOutput & Chr(9) & "Sender:" & (oRule.Conditions.SenderAddress.Enabled) & vbCrLf
End If



End If
Next
            
            
 For Each oAction In oRule.Actions
  If oAction.Enabled = True Then
    If oAction.ActionType = olRuleActionMoveToFolder Then
     sOutput = sOutput & Chr(9) & "Move To:" & (oAction.Folder.FolderPath) & vbCrLf
    End If
    
    If oAction.ActionType = olRuleActionImportance Then
     sOutput = sOutput & Chr(9) & "Set Importance:" & (oAction.Enabled) & vbCrLf
    End If

    If oAction.ActionType = olRuleActionAssignToCategory Then
      sOutput = sOutput & Chr(9) & "Set Category:" & (oAction.Enabled) & vbCrLf
    End If
    
    If oAction.ActionType = olRuleActionRunScript Then
      sOutput = sOutput & Chr(9) & "Run Script:" & (oAction.Enabled) & vbCrLf
    End If
    
    If oAction.ActionType = olRuleActionDeletePermanently Then
      sOutput = sOutput & Chr(9) & "Delete Perm:" & (oAction.Enabled) & vbCrLf
    End If
        
    If oAction.ActionType = olRuleActionCopyToFolder Then
      sOutput = sOutput & Chr(9) & "Copy to:" & (oAction.Folder.FolderPath) & vbCrLf
    End If
    
    If oAction.ActionType = olRuleActionForward Then
      sOutput = sOutput & Chr(9) & "Forward:" & (oAction.Enabled) & vbCrLf
    End If
    


  End If
 Next
            Print #1, sOutput
         Next
    Close #1
End Sub
Sub ListRules1()

End Sub
how do we achieve this magic?
Copy and paste the VB code into Outlook's VB Editor. You'll also need to allow macros 
to run. If you aren't asked if you want to allow macros when you open the VB editor, 
you'll need to change the macro security in Options, Trust Center to 'Always ask' 
about macros. We do not recommend the lowest security setting to never ask about
 macros.

When you paste the code, the text colors should be the same as seen in the code 
above. Red lines mean there is an error in the code.

Press ALT+F11 to open Outlook’s VB editor
If asked, you need to enable Macros
Expand Project1 and Microsoft Office Outlook Objects
Double-click on ThisOutlookSession
Copy the code and paste it into the VB editor window (right pane)
Save the changes (Ctrl+S or click the Save icon)
Press F8 or the Run button to run the macro

No comments: