Move Email in an IMAP Account

Jan 13, 2011
Reaction score
I have to write a VBA Script where I can move Email from an IMAP Account to an Folder within this IMAP Account, but I don't know where to start. Here is some code I found in the internet, but this code always shows that the folder doesn't exist:

Sub  MoveMessagesToFolder(strEmail As String, strOrdner As String)
	On  Error Resume Next
	'der MAPI-Folder legt den Ordner fest (z.B.  Zielordner)
	Dim objFolder As Outlook.MAPIFolder
	'dieser  MAPI-Folder legt den Ordner Posteingang fest
	Dim objInbox As  Outlook.MAPIFolder
	'mit den Namespaces wird der aktuelle  Arbeitsbereich
	'von Outlook festgelegt und stellt Methoden zur
	'An-  und Abmeldung in Outlook bereit.
	Dim objNS As Outlook.NameSpace
	'die  Items
	Dim objItem As Outlook.MailItem
	Set objNS =  Application.GetNamespace("MAPI")
	'Set objInbox =  objNS.GetDefaultFolder(olFolderInbox)
	Set objOtherInbox =  Session.Folders("[Email-Account-Name]\Posteingang")
	Set objFolder  = objOtherInbox.Folders(strOrdner)
	'Assume this is a  mail folder
	If objFolder Is Nothing Then
		MsgBox "This  folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
	End  If
	For Each objItem In  Application.ActiveExplorer.Session
		If  objFolder.DefaultItemType = olMailItem Then
			If  (objItem.Class = olMail) And (objItem.SenderEmailAddress = strEmail)  Then
				objItem.Move objFolder
			End If
		End  If
	Set objItem = Nothing
	Set  objFolder = Nothing
	Set objInbox = Nothing
	Set objNS =  Nothing
End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question