How can I create a script to move the currently active email in the Inbox to another folder in Outlook 2007

Keng picture Keng · Apr 21, 2009 · Viewed 9.2k times · Source

I sometimes get emails that I want to keep but to move them into the appropriate folder can be a pain. How can I execute a script that will move (like using C-S-v) the email I'm looking at into a certain folder called "buffer", for instance?

I'm using Outlook 2007.

thanks.


EDIT: there isn't any criteria that can be created to automate this process like through a rule. it is merely a judgment call I make as i'm staring at it.

Answer

JimmyPena picture JimmyPena · Nov 21, 2011

This code may work better.

In your code, objFolder may be equal to Nothing, yet you continue the procedure. Also, the For Each loop assumes that each item is a mail item.

Sub MoveSelectedMessagesToFolder()
  Dim objNS As Outlook.NameSpace
  Dim objFolder As Outlook.MAPIFolder
  Dim obj As Object
  Dim msg As Outlook.mailItem

  Set objNS = Application.GetNamespace("MAPI")
  On Error Resume Next
  Set objFolder = objNS.Folders.item("Personal Folders").Folders.item("Buffer")
  On Error GoTo 0

  If objFolder Is Nothing Then
    MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
    Exit Sub
  End If

  For Each obj In ActiveExplorer.Selection
    If TypeName(obj) = "MailItem" Then
      Set msg = obj
      msg.Move objFolder
    End If
  Next obj

End Sub