CopyTo Method

Microsoft Outlook Visual Basic

CopyTo Method

       

Copies the current folder in its entirety to the destination folder. Returns a MAPIFolder object that represents the new copy.

expression.CopyTo(DestinationFolder)

expression   Required. An expression that returns a MAPIFolder object (current folder).

DestinationFolder   Required MAPIFolder object (the destination folder for the copied folder).

Example

This Visual Basic for Applications example uses the CopyTo method to copy the current folder (in this case, the default Contacts folder) to the default Inbox folder.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myInboxFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myCurrentFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myNewFolder = myCurrentFolder.CopyTo(myInboxFolder)

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 myInboxFolder = myNameSpace.GetDefaultFolder(6)
Set myCurrentFolder = myNameSpace.GetDefaultFolder(10)
Set myNewFolder = myCurrentFolder.CopyTo(myInboxFolder)