Hello,
I want to copy new emails into a personal folder, and
I want to use VBA rather than the Rules Wizard. My code
follows, and I am NEW to VBA in Outlook.
When I get a new mail it tells me that the
Method 'Class' of object 'MailItem' failed
error code of -2147221233
TIA,
Per
Option Explicit
Private WithEvents olInboxItems As Outlook.Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub
Private Sub Application_Quit()
Set olInboxItems = Nothing
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
Dim objNS As NameSpace
Dim objInbox As MAPIFolder
Dim objArcFolder As MAPIFolder
Dim objCopiedItem As MailItem
If Item.Class = olMail Then ' <---- ***** HERE IS THE PROBLEM *****
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objArcFolder = objNS.Folders("Personal Folders").Folders("MAILArchive")
Set objCopiedItem = Item.Copy
objCopiedItem.Move objArcFolder
End If
Set objCopiedItem = Nothing
Set objArcFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub