cam
cam

Reputation: 9043

Outlook AddOn How to get selected emails?

I'm making an outlook addon and I'm trying to find a way to see which emails are selected, then be able to work with them through a foreach (or whatever). If this is not possible, is there a way to fetch all items in a folder and get access to that information easily? After that I need to move those items to another folder.

How would I go about doing this?

Upvotes: 3

Views: 5288

Answers (2)

Alvin567
Alvin567

Reputation: 335

Attached is my code to get the selected email from outlook messages. For the olitem feel free to modify as you need.

Sub ReplyMSG()
    Dim olItem As Outlook.MailItem
    Dim olReply As MailItem  ' Reply
    For Each olItem In Application.ActiveExplorer.Selection
        Set olReply = olItem.ReplyAll
        olReply.HTMLBody = "Reminder" & vbCrLf & olReply.HTMLBody
        olReply.Display
        'olReply.Send
    Next olItem
End Sub

Upvotes: 0

Heinzi
Heinzi

Reputation: 172468

You can use the Application.ActiveExplorer method to get the currently active Explorer window (= the thing that displays the list of mails). Then you can use the Explorer.Selection property to obtain the list of selected e-mails.

To move the mails, use the MailItem.Move method.

Upvotes: 6

Related Questions