Partager via


MoveTo Method

Moves a folder to the specified destination folder.

expression**.MoveTo(DestinationFolder)**

*expression    * Required. An expression that returns a MAPIFolder object.

DestinationFolder    Required. An expression that returns a MAPIFolder object. The destination folder for the folder that is being moved.

Example

TThis Visual Basic for Applications (VBA) example uses the MoveTo method to move the My Test Contacts folder in the default Contacts folder to the Inbox folder.

Sub MoveFolder()
    Dim myOlApp As New Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim myNewFolder As Outlook.MAPIFolder
    
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
    Set myNewFolder = myFolder.Folders.Add("My Test Contacts")
    myNewFolder.MoveTo myNameSpace.GetDefaultFolder(olFolderInbox)
End Sub

If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to move a new folder created in the Contacts folder to the default Inbox folder using VBScript code.

Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(10)
Set myNewFolder = myFolder.Folders.Add("My Contacts")
myNewFolder.MoveTo myNameSpace.GetDefaultFolder(6)

Applies to | MAPIFolder Object