Add Method
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Add method as it applies to the Actions object.
Creates a new action in the Actions collection and returns the new action as an Action object.
expression**.Add**
expression Required. An expression that returns an Actions collection object.
Add method as it applies to the AddressEntries object.
Adds a new entry to the AddressEntries collection and returns the new entry as an AddressEntry object.
expression.Add(Type, Name, Address)
expression Required. An expression that returns an AddressEntries object.
Type Required String. The type of the new entry.
Name Optional Variant. The name of the new entry.
Address Optional Variant. The address.
Add method as it applies to the Attachments object.
Creates a new address entry in the AddressEntries collection and returns the new address as an AddressEntry object.
Note New entries or changes to existing entries are not persisted in the collection until after calling the Update method.
expression**.Add**(Source, Type, Name, Address)
expression Required. An expression that returns an AddressEntries collection object.
Source Required String. The source of the attachment.
Type Required String. The type of the address entry.
Name Optional String. Display name for the address entry.
Address Optional String. The e-mail address of the address entry.
Add method as it applies to the Explorers object.
Creates a new instance of the Explorer window and returns a new instance of the window as an Explorer object.
expression.Add(Folder, DisplayMode)
expression Required. An expression that returns an Explorers collection.
Folder Required. The Variant object to display in the explorer window when it is created.
OlFolderDisplayMode
OlFolderDisplayMode can be one of these OlFolderDisplayMode constants. |
olFolderDisplayFolderOnly |
olFolderDisplayNoNavigation |
olFolderDisplayNormal |
Note The Folder argument can represent either a MAPIFolder object or the URL to that Folder.
Add method as it applies to the Folders object.
Creates a new folder in the Folders collection, and returns the new folder as a MAPIFolder object.
expression**.Add**(Name, Type)
expression Required. An expression that returns a Folders object.
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 olFolderDeletedItems, olFolderOutbox, and olFolderSentMail cannot be specified for this argument.)
Add method as it applies to the Inspectors object.
Creates a new inspector window and returns the resulting Inspector object.
expression**.Add**(Item)
expression Required. An expression that returns an Inspectors collection object.
Item Required Object. The item to display in the inspector window when it is created.
Add method as it applies to the ItemProperties object.
Adds an ItemProperty object to the ItemProperties collection.
expression.Add(Name, Type, AddToFolderFields, DisplayFormat)
expression Required. An expression that returns an ItemProperties object.
Name Required String. The name of the new item property object.
OlUserPropertyType
OlUserPropertyType can be one of these OlUserPropertyType constants. |
olCombination |
olCurrency |
olDateTime |
olDuration |
olFormula |
olKeywords |
olNumber |
olOutlookInternal |
olPercent |
olText |
olYesNo |
AddToFolderFields Optional Variant. Determined if the ItemProperty will appear as a field in a folder. If True, the field will appear in the folder.
DisplayFormat Optional Variant. Defines the format of the field as it appears in a given folder.
Add method as it applies to the Items object.
Creates a new Outlook item in the Items collection for the folder, and returns the new item. If not specified, the Type of the item defaults to the type of the folder, or to MailItem if the parent folder is not typed.
expression**.Add**(Type)
expression Required. An expression that returns an Items collection object.
Type Optional. Variant. The Outlook item type for the new item. Can be one of the following OlItemType constants: olAppointmentItem, olContactItem, olJournalItem, olMailItem, olNoteItem, olPostItem, or olTaskItem, one of the following OlOfficeDocItemsType constants: olExcelWorkSheetItem, olPowerPointShowItem, or olWordDocumentItem, or any valid message class. Specify the MessageClass to create custom forms.
Add method as it applies to the Links object.
Links an item to another item by adding a Link object to the Links collection associated with the latter item.
expression**.Add(Item)**
expression Required. An expression that returns a Links collection object.
Item Required Object. The item to be linked to the item associated with the Links collection.
Add method as it applies to the OutlookBarGroups object.
Adds a new, empty group to the Outlook Bar and returns the new group as an OutlookBarGroup object.
expression**.Add**(Name, Index)
oexpression Required. An expression that returns an OutlookBarGroups collection object.
Name Required String. The name of the group being created.
Index Optional Long. The position at which the new group will be inserted in the Outlook Bar. Position one is at the top of the bar.
Add method as it applies to the OutlookBarShortcuts object.
Adds a new shortcut to a group in the Outlook Bar and returns the new shortcut as an OutlookBarShortcut object.
expression**.Add**(Target, Name, Index)
expression Required. An expression that returns an OutlookBarShortcuts collection object.
Target Required Variant. The target of the shortcut being created.
Name Required String. The name of the shortcut being created.
Index Optional Long. The position at which the new shortcut will be inserted in the Outlook Bar group. Position one is at the top of the group.
The Target type depends on the shortcut type. If the type is MAPIFolder, the shortcut represents a Microsoft Outlook folder. If the type is a String, the shortcut represents a file-system path or a URL.
Add method as it applies to the Pages object.
Creates a new page in the Pages collection and returns the new object. The Pages collection is initially empty, and there is a limit of 5 customizable pages per collection.
expression**.Add**(Name)
expression Required. An expression that returns a Pages collection object.
Name Required. String. The name of the page.
Add method as it applies to the PropertyPages object.
Adds a new custom property page to the Microsoft Outlook Options dialog box or to the folder Properties dialog box.
expression**.Add**(Page, Title)
expression Required. An expression that returns a PropertyPages collection object.
Page Required Variant. The property page being added to the dialog box.
Title Optional String. The caption to be displayed on the property-page tab.
Add method as it applies to the Recipients object.
Creates a new recipient in the Recipients collection and returns the new recipient as a Recipient object.
expression**.Add**(Name)
expression Required. An expression that returns a Recipients collection object.
Name Required String. The display name of the recipient.
Add method as it applies to the UserProperties object.
Creates a new user property in the UserProperties collection, and returns the new property as a UserProperty object.
expression**.Add**(Name, Type, AddToFolderFields, DisplayFormat)
*expression * Required. An expression that returns a UserProperties collection object.
Name Required String. The name of the property.
OlUserPropertyType
OlUserPropertyType can be one of these OlUserPropertyType constants. |
olCombination |
olCurrency |
olDateTime |
olDuration |
olFormula |
olKeywords |
olNumber |
olOutlookInternal |
olPercent |
olText |
olYesNo |
AddToFolderFields Optional Boolean. True if the property will be added to the folder fields, False if not. The default value is True.
DisplayFormat Optional Long. The index format of the specified OlUserPropertyType constant.
Add method as it applies to the Views object.
Creates a new view. OlViewType.
expression.Add(Name, ViewType, SaveOption)
expression Required. An expression that returns a Views object.
Name Required String. The name of the new view.
OlViewType
OlViewType can be one of these OlViewType constants. |
olCalendarView |
olCardView |
olIconView |
olTableView |
olTimelineView |
SaveOption Optional olViewSaveOption. The save option that specifies the permissions of the new view.
Note The save option values are as follows:
olViewSaveOptionAllFoldersOfType The view can be accessed in all folders of this type.
olViewSaveOptionThisFolderEveryOne The view can be accessed by all users in this folder only.
olViewSaveOptionThisFolderOnlyMe The view can be accessed in this folder only by the user.
Example
As it applies to the Explorers object.
Remarks
The explorer window is initially hidden. You must call the Display of the Explorer object to make it visible.
The following Microsoft Visual Basic/Visual Basic for Applications example displays the Drafts folder in an explorer window without an Outlook Bar or Folder List.
Dim myOlApp As New Outlook.Application
Dim myExplorers As Outlook.Explorers
Dim myOlExpl As Outlook.Explorer
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = myOlApp.Explorers
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder _
(olFolderDrafts)
Set myOlExpl = myExplorers.Add _
(myFolder, olFolderDisplayNoNavigation)
myOlExpl.Display
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 myExplorers = Application.Explorers
Set myFolder = Application.GetNamespace("MAPI").GetDefaultFolder(16)
Set myOlExpl = myExplorers.Add(myFolder, 2)
myOlExpl.Display
As it applies to the Inspectors object.
Remarks
This method is essentially identical to the GetInspector property.
This Microsoft Visual Basic/Visual Basic for Applications example prompts the user for a company name, uses the Restrict method to locate all contact items in the Contacts folder with that name, and displays each one.
Dim myOlApp As New Outlook.Application
Answer = InputBox("Enter the company name")
Set myFolder = myOlApp.GetNamespace("MAPI") _
.GetDefaultFolder(olFolderContacts)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myRestrictItems = myItems.Restrict("[CompanyName] = " & Answer)
For x = 1 To myRestrictItems.Count
Set myInspector = myOlApp.Inspectors.Add(myRestrictItems.Item(x))
myInspector.Display
Next x
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.
Answer = InputBox("Enter the company name")
Set myFolder = _
Application.GetNamespace("MAPI").GetDefaultFolder(10)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myRestrictItems = myItems.Restrict("[CompanyName] = " & Answer)
For x = 1 To myRestrictItems.Count
Set myInspector = Application.Inspectors.Add(myRestrictItems.Item(x))
myInspector.Display
Next
As it applies to the Actions object.
This Visual Basic for Applications example creates a new mail message and uses the Add method to add an Action to it.
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAction = myItem.Actions.Add
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 myItem = Application.CreateItem(0)
Set myAction = myItem.Actions.Add
As it applies to the AddressEntries object.
This VBScript example uses the Click event of a CommandButton. The name in the To field of the form, as well as the person's manager, is located in the Global Address List. Both of these entries are added to the sender's Personal Address Book by using the Add method.
Sub CommandButton1_Click()
myName = Item.To
Set myNameSpace = Application.GetNameSpace("MAPI")
Set myGAddressList = myNameSpace.AddressLists("Global Address List")
Set myGEntries = myGAddressList.AddressEntries
Set myGEntry = myGEntries(myName)
myManager = myGEntry.Manager
Set myGEntry2 = myGEntries(myManager)
Set myPAddressList = myNameSpace.AddressLists("Personal Address Book")
Set myPEntries = myPAddressList.AddressEntries
'Add a new AddressEntry object to the personal
'address collection with the name, address, and
'manager of the name in your To field.
Set myPEntry = myPEntries.Add("Microsoft Mail Address", myName)
myPEntry.Address = myGEntry.Address
myPEntry.Manager = myGentry.Manager
'Update to persist the collection.
myPEntry.Update
'Now add the manager's info. to
'the Personal address collection.
Set myPEntry2 = myPEntries.Add("Microsoft Mail Address", myManager)
myPEntry2.Address = myGEntry2.Address
myPEntry2.Manager = myGentry2.Manager
myPEntry2.Update
End Sub
As it applies to the Links collection.
This Microsoft Visual Basic/Visual Basic for Applications example creates a new task item, and then prompts the user for the name of a contact to link to the item. If the contact is found, it is added to the item’s Links collection.
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myTask As Outlook.TaskItem
Dim myContact As Outlook.ContactItem
Set myTask = myOlApp.CreateItem(olTaskItem)
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
tempstr = InputBox("Enter the name of the contact to link to this task")
If tempstr <> "" Then
tempstr = "[Full Name] = """ & tempstr & """"
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myContact = myItems.Find(tempstr)
myTask.Links.Add myContact
myTask.Display
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 myTask = Application.CreateItem(3)
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(10)
tempstr = InputBox("Enter the name of the contact to link to this task")
If tempstr <> "" Then
tempstr = "[Full Name] = """ & tempstr & """"
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myContact = myItems.Find(tempstr)
myTask.Links.Add myContact
myTask.Display
As it applies to the Folders collection.
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!"
As it applies to the Items collection
This Visual Basic for Applications example gets the current Contacts folder and adds a new ContactItem object to it.
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myFolder.Items.Add
This Visual Basic for Applications example adds a custom form to the default Tasks folder.
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
myNamespace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Task.myTask")
As it applies to the OutlookBarGroups collection.
This Microsoft Visual Basic/Visual Basic for Applications example adds a group named Marketing as the second group in the Outlook Bar.
Dim myOlApp As New Outlook.Application
Dim myolBar As Outlook.OutlookBarPane
Set myolBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
myolBar.Contents.Groups.Add "Marketing", 2
If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.
Set myolBar = Application.ActiveExplorer.Panes.Item("OutlookBar")
myolBar.Contents.Groups.Add "Marketing", 2
As it applies to the OutlookBarShortcuts collection.
The following Microsoft Visual Basic/Visual Basic for Applications example adds a shortcut to the Microsoft home page on the Web.
Dim myOlApp As New Outlook.Application
Dim myOlBar As Outlook.OutlookBarPane
Dim myolGroup As Outlook.OutlookBarGroup
Dim myOlShortcuts As Outlook.OutlookBarShortcuts
Set myOlBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
Set myolGroup = myOlBar.Contents.Groups.Item(1)
Set myOlShortcuts = myolGroup.Shortcuts
myOlShortcuts.Add "http://www.microsoft.com", _
"Microsoft Home Page", 3
If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.
Set myOlBar = _
Application.ActiveExplorer.Panes.Item("OutlookBar")
Set myolGroup = myOlBar.Contents.Groups.Item(1)
Set myOlShortcuts = myolGroup.Shortcuts
myOlShortcuts.Add "http://www.microsoft.com", _
"Microsoft Home Page", 3
As it applies to the Recipients collection.
This Visual Basic for Applications example creates a new mail message, uses the Add method to add "Allison Klein" as a To recipient, and displays the message.
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add("Allison Klein")
myItem.Display
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 myItem = Application.CreateItem(0)
Set myRecipient = myItem.Recipients.Add("Allison Klein")
myItem.Display
As it applies to the UserProperties collection.
This Visual Basic for Applications example creates a new ContactItem object and adds "LastDateSpokenWith" as a user property.
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olContactItem)
Set myUserProperty = myItem.UserProperties _
.Add("LastDateSpokenWith", olDateTime)
This Visual Basic for Applications example creates a new ContactItem object and adds "Notes" as a user property. The Value is set by accessing the index of the new property.
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olContactItem)
Set myUserProperty = myItem.UserProperties _
.Add("Notes", olText)
myItem.UserProperties(1).Value = "Neighbor"
As it applies to the Views object.
The following example creates a new view called New Table and stores it in a variable called objNewView.
Sub CreateView()
'Creates a new view
Dim olApp As Outlook.Application
Dim objName As NameSpace
Dim objViews As Views
Dim objNewView As View
Set olApp = Outlook.Application
Set objName = olApp.GetNamespace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
Set objNewView = objViews.Add(Name:="New Table", _
ViewType:=olTableView, SaveOption:=olViewSaveOptionThisFolderEveryone)
End Sub