Error Moving messages from inbox to personal folders.

  • Thread starter Thread starter gorbunok
  • Start date Start date
G

gorbunok

I wrote a macro that searches all the personal Folders for a
conversation
that a new message in Inbox belongs to. If it finds it it moves it
there.

It works pretty good except that pretty often an error message pops up
that says
Actioned Failed and my macro get disabled in the rules wizard.. the
code is bellow. I can't find a way to debug this


Sub NewMessageMoveByThread(mail As Outlook.MailItem)
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")

Set myPersonalFolder = myNamespace.Folders.Item("Personal
Folders")


Set allPersonalFolders = myPersonalFolder.Folders

If mail.UnRead And (Trim(mail.Subject) <> "" Or
Trim(mail.Subject) <> "Re:") Then
For Each folder In allPersonalFolders
If Not folder.Name = "Deleted Items" Then
If Not
TypeName(folder.Items.Find("[ConversationTopic] = """ &
mail.ConversationTopic & """")) = "Nothing" Then
mail.Move folder
Exit For
End If
End If
Next
End If
End Sub
 
Debugging is hard if you're doing too much in each statement. You should use
a separate statement to get each object, then work with its properties and
methods. Instead of

If Not TypeName(folder.Items.Find("[ConversationTopic] = """ &
mail.ConversationTopic & """")) = "Nothing" Then

use

strFind = ("[ConversationTopic] = """ & mail.ConversationTopic & """")
Debug.Print strFind ' for testing
Set objFoundIt = folder.Items.Find(strFind)
If Not objFoundIt Is Nothing Then
' your code continues here

Also, put an On Error Resume Next statement at the beginning of the
procedure to add minimum error handling.
 
Back
Top