Outlook Auto Email Mover

  • 13 years ago

    hey guys

     Ive been trying to create a macro that will move selected emails from one folder to another, across multiple mailboxes.

    So far I have written the following and it moves the email from 1 mailbox to a predefined mailbox. Can I get VB to give me a list of target fodlers so i can select where to move the email to instead of having it hard written?

     

    Sub testfolder()

    On Error Resume Next

     

        Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder

        Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
     

        Set objNS = Application.GetNamespace("MAPI")

        Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

        Set objFolder = objInbox.Folders("Roll Outs")

    'Assume this is a mail folder

     

        If objFolder Is Nothing Then

            MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"

        End If

     

        If Application.ActiveExplorer.Selection.Count = 0 Then

            'Require that this procedure be called only when a message is selected

            Exit Sub

        End If

     

        For Each objItem In Application.ActiveExplorer.Selection

            If objFolder.DefaultItemType = olMailItem Then

                If objItem.Class = olMail Then

                    objItem.Move objFolder

                End If

            End If

        Next

     

        Set objItem = Nothing

        Set objFolder = Nothing

        Set objInbox = Nothing

        Set objNS = Nothing

     

    End Sub

     

    Thanks for your help guys

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”