Search code examples
vbaoutlookhtml-emailoffice-automation

Automating Actions in Outlook 2013


I have a folder of emails in outlook, and I want to be able to apply the same action to each email within the folder, however I notice that there is no macro recorder within Outlook's Developer options.

The process that I am currently undertaking involves opening each email (as it contains HTML content and I want to print it in a document quality image) selecting "View in browser" from the "Actions" tab, and printing from Internet Explorer.

Is there a way to iterate this action within Outlook for each email within the folder? I have no clue as to how to set about this without some way of recording my actions to get an idea of how to refer to things within the Outlook module...


Solution

  • You will need to learn a little bit about Outlook's Object model Getting Started with VBA in Outlook 2010. Here is a little code to get you started. This macro will loop through all the items in a folder and check the email address of the recipient and set the flag

    Sub SetFlagIcon()
        Dim mpfInbox As Outlook.Folder
        Dim obj As Outlook.MailItem
        Dim i As Integer
        Set mpfInbox = Application.GetNamespace("MAPI").Folders("Jeanno").Folders("Sent Mail")
        ' Loop all items in the Inbox\Test Folder
        For i = 1 To mpfInbox.Items.Count
            If mpfInbox.Items(i).Class = olMail Then
                Set obj = mpfInbox.Items.Item(i)
                For Each Recipient In obj.Recipients
                    If Recipient.Address = "someone@email" Then
                        'Set the yellow flag icon
                        obj.FlagIcon = olYellowFlagIcon
                        obj.Save
                    End If
                Next Recipient
            End If
        Next
    End Sub