VB Macro for outlook to move x #of messages to a folder.

Sub MoveMail()

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Long
Dim strDestFolder As String

Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace(“MAPI”)
Set objSourceFolder = objNamespace.Folders(“archive@csinet.ca”).Folders(“Inbox”).Folders(“Old”)

For intCount = 1 To objSourceFolder.Items.Count – objSourceFolder.Items.Count + 1
Set objVariant = objSourceFolder.Items.Item(intCount)
DoEvents
If objVariant.Class = olMail Then
Set objDestFolder = objNamespace.Folders(“archive@csinet.ca”).Folders(“Inbox”)
objVariant.Move objDestFolder
‘count the # of items moved
lngMovedItems = lngMovedItems + 1
Set objDestFolder = Nothing
‘End If
End If
Next

‘ Display the number of items that were moved.
MsgBox “Moved ” & lngMovedItems & ” messages(s).”

End Sub

Jeremy Tirrell

Read more posts by this author.