Move Method

Microsoft Outlook Visual Basic

Show All

Move Method

       

Moves an Outlook item to a new folder.

expression.Move(DestFldr)

expression   Required. An expression that returns one of the objects in the Applies To list.

DestFldr   Required. An expression that returns a MAPIFolder object. The destination folder.

Example

This Visual Basic for Applications example uses GetDefaultFolder to return the MAPIFolder object that represents the default folder. It then uses the Find and FindNext methods to find all messages sent by Mike Nash and uses the Move method to move all mail messages sent by Mike Nash from the default Inbox folder to the Personal Mail folder.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Mike Nash'")
While TypeName(myItem) <> "Nothing"
    myItem.Move myDestFolder
    Set myItem = myItems.FindNext
Wend

If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNameSpace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(6)
Set myItems = myInbox.Items
Set myDestFolder = myInbox.Folders("Personal Mail")
Set myItem = myItems.Find("[SenderName] = 'Mike Nash'")
While TypeName(myItem) <> "Nothing"
    myItem.Move myDestFolder
    Set myItem = myItems.FindNext
Wend