Consulting

Results 1 to 3 of 3

Thread: Outlook Object model

  1. #1
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    113
    Location

    Outlook Object model

    Does anyone have any info on the Outlook Object model?
    Looking for a way to export rules into a human readable format (at least)?

    TIA

    I have managed to cobble the below together from snippets on the net, but TBH am getting lost. I am not a developer, but a dabbler.

    Sub TestRule()
        Dim olRules As Outlook.rules
        Dim olRule As Outlook.Rule
        Dim iRule As Integer, iAction As Integer, iException As Integer, iRuleAction As Integer
        Set olRules = Application.Session.DefaultStore.GetRules
        'Set olRule = olRules.item("TestRule")
        For iRule = 1 To 1 '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
                 Debug.Print "ActionType: " & olRules.item(iRule).RuleActions.item(iAction)
                 For iRuleAction = 1 To olRules.item(iRule).RuleActions.item(iRuleAction).Count
                     Debug.Print "RuleACtions: " & olRules.item(iRule).RuleActions.item(iRuleAction)
                 Next
             Next
             Debug.Print olRules.item(iRule).Exceptions.Count
             printArray olRules(iRule).Conditions.Body.Text
             printArray olRules(iRule).Conditions.MessageHeader.Text
        Next
        Set olRules = Nothing
        Set olRule = Nothing
    End Sub
    
    Private Sub printArray(ByRef pArr As Variant)
        Dim readString As Variant
        If (IsArray(pArr)) Then
            'check if the passed variable is an array
            For Each readString In pArr
                If TypeName(readString) = "String" Then 'check if the readString is a String variable
                    Debug.Print readString
                End If
            Next
        End If
    End Sub
    Last edited by Aussiebear; 08-30-2024 at 03:58 PM. Reason: Tidy up presentation

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    372
    Location
    1. errors if there are no rules

    2. doesn't like RuleActions "Object doesn't support this property or method." My understanding of this property is that it is a collection of available rule actions. The entire collection is associated with each rule. Each action will be flagged as enabled if it is set as such for specific rule. I expect will have to enumerate the collection and output its identifier and enabled status. Something like:
    Dim olRules As Outlook.Rules, olRule As Outlook.Rule, olR As Outlook.RuleActions, olA As RuleAction
    Set olRules = Application.Session.DefaultStore.GetRules
    For Each olRule In olRules
        Set olR = olRule.Actions
        For Each olA In olR
            Debug.Print olRule.Name, olA.ActionType, olA.Enabled
        Next
    Next
    See docs for ActionType constants https://learn.microsoft.com/en-us/of...ruleactiontype
    Last edited by June7; 08-31-2024 at 10:37 AM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Contributor
    Joined
    Nov 2020
    Location
    Swansea,South Wales,UK
    Posts
    113
    Location
    Hi @June7
    Trying to assist a member in another forum.
    I now have this so far.

    Sub TestRule()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 strTab As String
    
    
    strTab = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
    
    
    Set olRules = Application.Session.DefaultStore.GetRules
    'Set olRule = olRules.item("TestRule")
    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 And olRules.item(iRule).Actions(iAction).ActionType = 1 Then
                Debug.Print "Rule: " & olRules.item(iRule).Name & strTab & "Folder: " & olRules.item(iRule).Actions(iAction).Folder.FolderPath
                Exit For
            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
    Set oAction = Nothing
    Set olRules = Nothing
    Set olRule = Nothing
    End Sub
    which produces
    Rule: XE Currency                               Folder: \\Personal Folders\Inbox\Gmail\XERule: AirBnB                                Folder: \\Personal Folders\Inbox\Gmail\AirBnB
    Rule: Google Support                                Folder: \\Personal Folders\Inbox\Gmail\Google Support
    So I think I have got what they are looking for.
    Will have to wait an see.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •