Folders Property

Microsoft Outlook Visual Basic

Folders Property

       

Returns the Folders collection that represents all the folders contained in the specified folder or name space. The NameSpace object is the root of all the folders for the given name space.

expression.Folders

expression   Required. An expression that returns a MAPIFolder object or a NameSpace object.

Example

This Visual Basic for Applications example uses the Add method to add the new folder named "My Contacts" to the current (default) Contacts folder.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
Set myNewFolder = myFolder.Folders.Add("My Contacts")

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 myFolder = myNamespace.GetDefaultFolder(10)
Set myNewFolder = myFolder.Folders.Add("My Contacts")

This Visual Basic for Applications example uses the Add method to add two new folders in the Tasks folder. The first folder, "Notes Folder", will contain note items. The second folder, "Contacts Folder", will contain contact items. If the folders already exist, a message box will inform the user.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderTasks)
On Error GoTo ErrorHandler
Set myNotesFolder = myFolder.Folders.Add ("Notes Folder", olFolderNotes)
On Error GoTo ErrorHandler
Set myContactFolder = myFolder.Folders.Add ("Contacts Folder", olFolderContacts)
Exit Sub
ErrorHandler:
    MsgBox "This folder already exists!"