I setup the code below to fire off from an Outlook rule when an email
arrives in the 'Inbox'. The code does work to a point. It does copy
email messages when they arrive in the 'Inbox' to the 'Archive->2005
Mail' folder. But, it seems to make copies of existing email in the
'2005 Mail' folder and I don't know why. My 'FOR NEXT" loop seems like
it's right, so I'm not sure why it's doing that.
Dim i As Integer
Dim count As Integer
Dim intCount As Integer
Dim objApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI")
Dim objInbox As Outlook.MAPIFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim objArchive As Outlook.MAPIFolder = objNS.Folders("Personal
Folders").Folders("Archive").Folders("2005 Mail")
Dim oInbox As Outlook.Folders = objInbox.Folders
Dim objItems As Outlook.Items = objInbox.Items
Dim oMessage As Outlook.MailItem
intCount = objItems.Count
For i = intCount To 1 Step -1
oMessage = objItems.Item(i)
oMessage.Copy()
oMessage.Move(objArchive)
Next
objNS.Logoff()
objApp = Nothing
objNS = Nothing
objItems = Nothing
oInbox = Nothing
I researched the Outlookcode.com site for a solution, but didn't really
find anything.
|