0% found this document useful (0 votes)
166 views5 pages

NameSpace Object

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 5

NameSpace Object

See AlsoPropertiesMethodsEventsSpecifics NameSpace Multiple objects Represents an abstract root object for any data source. The object itself provides methods for logging in and out, accessing storage objects directly by ID, accessing certain special default folders directly, and accessing data sources owned by other users.

Using the NameSpace Object


Use GetNameSpace ("MAPI") to return the Outlook NameSpace object from the Application object. The only data source supported is MAPI, which allows access to all Outlook data stored in the user's mail stores.

Properties

Folders Property
See AlsoApplies ToExampleSpecifics 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."

End Sub

Resume Next

Methods
GetDefaultFolder Method
See AlsoApplies ToExampleSpecifics Returns a MAPIFolder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on. Note To return a specific non-default folder, use the Folders collection. expression.GetDefaultFolder(FolderType) expression FolderType return. Required. An expression that returns a NameSpace object. Required OlDefaultFolders. The type of default folder to

OlDefaultFolders can be one of these OlDefaultFolders constants. olFolderCalendar olFolderContacts olFolderDeletedItems olFolderDrafts olFolderInbox olFolderJournal olFolderNotes olFolderOutbox olFolderSentMail olFolderTasks olPublicFoldersAllPublicFolders olFolderJunk

Example
This Visual Basic for Applications (VBA) example uses the CurrentFolder property to change the displayed folder to the user's default Calendar folder.
Sub ChangeCurrentFolder() Dim myolApp As Outlook.Application Dim myNamespace As Outlook.NameSpace Set myolApp = CreateObject("Outlook.Application") Set myNamespace = myolApp.GetNamespace("MAPI") Set myolApp.ActiveExplorer.CurrentFolder = _ myNamespace.GetDefaultFolder(olFolderCalendar) 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 code.
Set myNameSpace = Application.GetNameSpace("MAPI") Set Application.ActiveExplorer.CurrentFolder = _ myNameSpace.GetDefaultFolder(9)

This VBA example returns the first folder in the Tasks Folders collection.
Sub Dim Dim Dim Dim Set Set Set DisplayATaskFolder() myolApp As Outlook.Application myNamespace As Outlook.NameSpace myTasks As Outlook.MAPIFolder myFolder As Outlook.MAPIFolder myolApp = CreateObject("Outlook.Application") myNamespace = myolApp.GetNamespace("MAPI") myTasks = myNamespace.GetDefaultFolder(olFolderTasks)

Set myFolder = myTasks.Folders(1) myFolder.Display End Sub

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy