Thursday, February 14, 2008

Outlook: Move Items to Folder (with GUI folder list and not inputbox)

I was searching for a Macro online for Outlook mail items moved to different folders.

Have seen few codes that performs the same but with this code I used the GUI folder listing instead of prompting for an inputbox to avoid errors as most users are not aware of the Folder paths.

I submitted the code to OutlookCodeDotCom: Moving mail items to specified folder

It has 30++ downloads so far... not bad!

  1. Sub MoveMailToFolders()
  2. Dim objNS As Outlook.NameSpace
  3. Dim MyFolder As Outlook.MAPIFolder
  4. Dim objItem As Outlook.MailItem
  5. Dim ctr As Integer
  6. On Error Resume Next
  7. ctr = 0
  8. Set objNS = Application.GetNamespace("MAPI")
  9. Set MyFolder = objNS.PickFolder
  10. MsgBox "The selected mail item(s) will be moved to: " & vbCrLf & vbCrLf & _
  11. "Folder Path: " & MyFolder.FolderPath & vbCrLf & _
  12. "Folder Name: " & MyFolder.Name _
  13. , vbOKOnly + vbInformation, "Outlook Help"
  14. For Each objItem In Application.ActiveExplorer.Selection
  15. If MyFolder.DefaultItemType = olMailItem Then
  16. If objItem.Class = olMail Then
  17. ctr = ctr + 1
  18. objItem.Move MyFolder
  19. End If
  20. End If
  21. Next
  22. MsgBox "Moved: " & ctr & " mail item(s) to: " & MyFolder.Name, vbInformation, "Outlook Help"
  23. Set objNS = Nothing
  24. Set MyFolder = Nothing
  25. End Sub


Then using the Customize option on the toolbar, you can create a button for the Macro and assign a shortcut key to it!


If at first you fail, call it version 1.0