Add Method
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. Note New entries or changes to existing entries are not persisted in the collection until after calling the Update method.
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 attachment in the Attachments collection and returns the new attachment as an Attachment object.
expression**.Add**(Source, Type, Position, DisplayName)
expression Required. An expression that returns an Attachments collection object.
Source Required String. The source of the attachment.
Type Optional String. The type of the attachment.
Position Optional String. In e-mail messages using Microsoft Outlook Rich Text format, position where the attachment should be placed. A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. A value 'n' greater than the number of characters in the body of the e-mail item specifies that the attachment should be placed at the end. A value of 0 makes the attachment hidden.
DisplayName Optional String. This name is displayed in an Inspector object for the attachment if the mail item is in Rich Text format. If the mail item is in Plain Text or HTML format, then the attachment is displayed using the name in the Source parameter.
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, olPublicFoldersAllPublicFolders, or olFolderTasks. (The constants olFolderDeletedItems, olFolderOutbox, olFolderJunk, olFolderConflicts, olFolderLocalFailures, olFolderServerFailures, olFolderSyncIssues, 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. Determines if the item property will be added to the folder fields.
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: olWordDocumentItem, olExcelWorkSheetItem, olPowerPointShowItem, or any valid message class. Specify a MessageClass to create custom forms.
Add method as it applies to the Links object.
Links a contact 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 Shortcuts pane 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 Shortcuts pane. 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 Shortcuts pane 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 Shortcuts pane 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.
Note You can only add user-defined fields to Outlook items. User-defined fields cannot be added to Microsoft Office document items such as Microsoft Word, Microsoft Excel, or Microsoft PowerPoint files even though you can programmatically create those items using the olOfficeDocItemsType constants. You will receive an error when you try to programmatically add a user-defined field to a DocumentItem object.
Add method as it applies to the Views object.
Creates a new view in the Views collection, and returns the new view as a View object.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 Attachments object.
Remarks
For e-mail messages in Microsoft Outlook Rich Text format, a value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. A value 'n' greater than the number of characters in the body of the mail item specifies that the attachment should be placed at the end. A value of 0 makes the attachment hidden.
The following Microsoft Visual Basic /Visual Basic for Applications (VBA) example creates a mail item, adds an attachment, and displays it. To run this example, make sure a file called Test.Doc exists in the C:\ folder.
Sub AddAttachment()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Test.doc", _
olByValue, 1, "Test"
myItem.Display
End Sub
As it applies to the Explorers object.
Remarks
The explorer window is initially hidden. You must call the Display method of the Explorer object to make it visible.
The following Visual Basic/VBA example displays the Drafts folder in an explorer window without a Navigation Pane or Folder List.
Sub DisplayDrafts()
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
End Sub
If you use Microsoft Visual Basic Scripting Edition (VBScript) in an 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 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.
Sub DisplayMyContacts()
Dim myOlApp As New Outlook.Application
Dim myFolder As MAPIFolder
Dim myItems As Items
Dim myRestrictItems As Items
Dim answer As String
Dim filter As String
Dim myInspector As Inspector
Dim x As Integer
answer = InputBox("Enter the company name")
Set myFolder = myOlApp.GetNamespace("MAPI") _
.GetDefaultFolder(olFolderContacts)
filter = "[MessageClass] = 'IPM.Contact' AND [CompanyName] = '" & answer & "'"
Set myItems = myFolder.Items
Set myRestrictItems = myItems.Restrict(filter)
For x = 1 To myRestrictItems.Count
Set myInspector = myOlApp.Inspectors.Add(myRestrictItems.Item(x))
myInspector.Display
Next x
End Sub
As it applies to the Actions object.
This VBA example creates a new mail message and uses the Add method to add an Action to it. To run this example without any errors, replace 'Dan Wilson' with a valid recipient name.
Sub AddAction()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim myAction As Outlook.Action
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAction = myItem.Actions.Add
myAction.Name = "Link Original"
myAction.ShowOn = olMenuAndToolbar
myAction.ReplyStyle = olLinkOriginalItem
myItem.To = "Dan Wilson"
myItem.Send
End Sub
If you use VBScript in an 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 myItem = Application.CreateItem(0)
Set myAction = myItem.Actions.Add
myAction.Name = "Link Original"
myAction.ShowOn = 2
myAction.ReplyStyle = 4
myItem.To = "Kim Buhler"
myItem.Send
As it applies to the Links collection.
This Visual Basic/VBA 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.
Sub AddLink()
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
Dim myItems As Outlook.Items
Dim tempstr As String
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
End If
End Sub
If you use VBScript in an 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 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 VBA example uses the Add method to add the new folder named "My Contacts" to the current (default) Contacts folder.
Sub AddContactsFolder()
Dim myOlApp As New 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 Contacts")
End Sub
If you use VBScript in an 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.
Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(10)
Set myNewFolder = myFolder.Folders.Add("My Contacts")
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 myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myNotesFolder As Outlook.MAPIFolder
Dim myContactsFolder As Outlook.MAPIFolder
Dim myPublicFolder 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("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
As it applies to the Items collection.
This VBA example gets the current Contacts folder and adds a new ContactItem object to it and sets some initial values in the fields based on another contact. To run this example without any error, replace 'Dan Wilson' with a valid contact name that exists in your Contacts folder.
Sub AddContact()
Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.ContactItem
Dim myOtherItem As Outlook.ContactItem
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
Set myOtherItem = myFolder.Items("Dan Wilson")
Set myItem = myFolder.Items.Add
myItem.CompanyName = myOtherItem.CompanyName
myItem.BusinessAddress = myOtherItem.BusinessAddress
myItem.BusinessTelephoneNumber = myOtherItem.BusinessTelephoneNumber
myItem.Display
End Sub
This VBA example adds a custom form to the default Tasks folder.
Sub AddForm()
Dim myOlApp As New outlook.Application
Dim myNamespace As outlook.NameSpace
Dim myItems As outlook.Items
Dim myFolder As outlook.MAPIFolder
Dim myItem As outlook.TaskItem
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = _
myNamespace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Task.myTask")
End Sub
As it applies to the OutlookBarGroups collection.
This Visual Basic/VBA example adds a group named Marketing as the last group in the Shortcuts pane.
Sub AddGroup()
Dim myOlApp As New Outlook.Application
Dim myolBar As Outlook.OutlookBarPane
Set myolBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
myolBar.Contents.Groups.Add "Marketing", myolBar.Contents.Groups.Count + 1
End Sub
If you use VBScript in an Outlook form, 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", myolBar.Contents.Groups.Count + 1
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.
Sub AddShortcut()
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", 1
End Sub
If you use VBScript in an Outlook form, you do not create the Application object. This example shows how to perform the same task using VBScript code.
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", 1
As it applies to the Recipients collection.
This VBA example creates a new mail message, uses the Add method to add 'Dan Wilson' as a To recipient, and displays the message. To run this example without errors, replace 'Dan Wilson' with a valid recipient name.
Sub CreateStatusReportToBoss()
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim myRecipient As Outlook.Recipient
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add("Dan Wilson")
myItem.Subject = "Status Report"
myItem.Display
End Sub
If you use VBScript in an 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 myItem = Application.CreateItem(0)
Set myRecipient = myItem.Recipients.Add("Dan Wilson")
myItem.Subject = "Status Report"
myItem.Display
As it applies to the UserProperties collection.
This VBA example creates a new ContactItem object and adds "LastDateSpokenWith" as a custom property.
Sub AddUserProperty()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.ContactItem
Dim myUserProperty As Outlook.UserProperty
Set myItem = myOlApp.CreateItem(olContactItem)
Set myUserProperty = myItem.UserProperties _
.Add("LastDateSpokenWith", olDateTime)
myItem.Display
End Sub
This VBA example creates a new ContactItem object and adds "Notes" as a user property. The Value is set by changing the Value property of the UserProperty object.
Sub AddUserProperty()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.ContactItem
Dim myUserProperty As Outlook.UserProperty
Set myItem = myOlApp.CreateItem(olContactItem)
Set myUserProperty = myItem.UserProperties _
.Add("Notes", olText)
myUserProperty.Value = "Neighbor"
myItem.Display
End Sub
As it applies to the Views object.
The following Visual Basic for Applications (VBA) 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 Outlook.NameSpace
Dim objViews As Outlook.Views
Dim objNewView As Outlook.View
Set olApp = New 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
Applies to | Actions Object | AddressEntries Object | Attachments Object | Explorers Object | Folders Object | Inspectors Object | ItemProperties Collection | Items Object | Links Object | OutlookBarGroups Object | OutlookBarShortcuts Object | Pages Object | PropertyPages Object | Recipients Object | UserProperties Object | Views Collection