Folders.Add method (Outlook)
Creates a new folder in the Folders collection.
Syntax
expression.Add (Name, Type)
expression A variable that represents a Folders object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
Name | Required | String | The display name for the new folder. |
Type | Optional | Long | The Outlook folder type for the new folder. If the folder type is not specified, the new folder will default to the same type as the folder in which it is created. Can be one of the following OlDefaultFolders constants: olFolderCalendar, olFolderContacts, olFolderDrafts, olFolderInbox, olFolderJournal, olFolderNotes, or olFolderTasks. The constants olFolderConflicts, olFolderDeletedItems, olFolderJunk, olFolderLocalFailures, olFolderManagedEmail, olFolderOutbox, olFolderRssSubscriptions, olFolderSentMail, olFolderServerFailures, olFolderSyncIssues, olFolderToDo, and olPublicFoldersAllPublicFolders cannot be specified for this argument. |
Return value
A Folder object that represents the new folder.
Example
This VBA example uses the Add method to add the new folder named "My Contacts" to the current (default) Contacts folder.
Sub AddContactsFolder()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myNewFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myNewFolder = myFolder.Folders.Add("My Contacts")
End Sub
This VBA example uses the Add method to add three new folders in the Tasks folder. The first folder, Notes Folder, will contain note items. The second folder, Contacts Folder, will contain contact items. The third folder, Public Folder, will be a public folder. If the folders already exist, a message box will inform the user.
Sub AddFolders()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myNotesFolder As Outlook.Folder
Dim myContactsFolder As Outlook.Folder
Dim myPublicFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
On Error GoTo ErrorHandler
Set myNotesFolder = myFolder.Folders.Add("Notes Folder", olFolderNotes)
Set myContactsFolder = myFolder.Folders.Add("Contacts Folder", olFolderContacts)
Set myPublicFolder = myFolder.Folders.Add("Public Folder", olPublicFoldersAllPublicFolders)
Exit Sub
ErrorHandler:
MsgBox "This folder already exists!"
Resume Next
End Sub
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기