Sub TestRule()
''From Gasman https://www.access-programmers.co.uk/forums/threads/outlook.332069/#post-1934352
''modified by Pat Hartman to export to csv
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Dim iRule As Integer, iAction As Integer, iException As Integer, iRuleAction As Integer
Dim oAction As Object
'''
Dim CountItems As Integer
Dim FileName As String
Dim FileNumber As Long
Dim strRecord As String
Dim strPrint As String
On Error GoTo ErrProc
Set olRules = Application.Session.DefaultStore.GetRules
'Set olRule = olRules.item("TestRule")
CountItems = 0
FileName = "C:\Data\UsefulDatabases\Collections\OutlookRules.csv"
FileNumber = FreeFile() 'get next available file number
Open FileName For Output As FileNumber 'Open output file
strRecord = "SeqNum, Rule, Folder, From"
Print #FileNumber, strRecord ' print column names as first record
For iRule = 1 To olRules.Count 'Each olRule In olRules
' Debug.Print olRules.item(iRule).Name 'TypeName(iRule)
' Debug.Print olRules.item(iRule).Enabled
' Debug.Print olRules.item(iRule).Actions.Count
For iAction = 1 To olRules.Item(iRule).Actions.Count
'Set oAction = olRules.item(iRule).Action
If olRules.Item(iRule).Actions(iAction).Enabled = True And olRules.Item(iRule).Actions(iAction).ActionType = 1 Then
strPrint = "Rule: " & olRules.Item(iRule).Name & vbTab & vbTab & vbTab & vbTab & "Folder: " & olRules.Item(iRule).Actions(iAction).Folder.FolderPath
strPrint = strPrint & "Sender " & olRules.Item(iRule).Conditions.From.Recipients.Item(1).Address
Debug.Print strPrint
CountItems = CountItems + 1
strRecord = CountItems & "," & olRules.Item(iRule).Name & "," & olRules.Item(iRule).Actions(iAction).Folder.FolderPath & "," & olRules.Item(iRule).Conditions.From.Recipients.Item(1).Address
Print #FileNumber, strRecord
End If
'Debug.Print "ActionType: " & olRules.item(iRule).RuleActions.item(iAction)
Next
'Debug.Print olRules.item(iRule).Exceptions.Count
'printArray olRules(iRule).Conditions.Body.Text
'printArray olRules(iRule).Conditions.MessageHeader.Text
Next
ExitProc:
Debug.Print "Count = " & CountItems
Close #FileNumber
Set oAction = Nothing
Set olRules = Nothing
Set olRule = Nothing
Exit Sub
ErrProc:
Select Case Err.Number
Case Else
MsgBox Err.Number & "--" & Err.Description
Resume Next
End Select
End Sub