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 (VBA) example uses the Add method to add the new folder named "My Personal Contacts" to the default Contacts folder.
Sub CreatePersonalContacts()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myNewFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
Set myNewFolder = myFolder.Folders.Add("My Personal Contacts")
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 perform the same task using VBScript.
Sub CommandButton1_Click()
Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(10)
Set myNewFolder = myFolder.Folders.Add("My Personal Contacts")
End Sub
This VBA example uses the Add method to add two new folders in the Tasks folder. The first folder, "My Notes Folder", will contain note items. The second folder, "My Contacts Folder", will contain contact items. If the folders already exist, a message box will inform the user.
Sub CreateFolders()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myNotesFolder As Outlook.MAPIFolder
Dim myContactFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderTasks)
On Error GoTo ErrorHandler
Set myNotesFolder = myFolder.Folders.Add("My Notes Folder", olFolderNotes)
Set myContactFolder = myFolder.Folders.Add("My Contacts Folder", olFolderContacts)
Exit Sub
ErrorHandler:
MsgBox "Error creating the folder. The folder may already exist."
Resume Next
End Sub