Remove Method

Microsoft Outlook Visual Basic

Show All

Remove Method

       

Remove method as it applies to the Actions, Attachments, Folders, Items, ItemProperties, Pages, Recipients, and UserProperties objects.

Removes an object from one of the above collections.

expression.Remove(Index)

expression   Required. An expression that returns one of the above collections.

Index  Required Long. The index value of the object within the collection.

Remove method as it applies to the Links, OutlookBarGroups, OutlookBarShortcuts, PropertyPages, Reminders, and Views objects.

Removes an object from the specified list.

expression.Remove(Index)

expression   Required. An expression that returns one of the above objects.

Index  Required Variant. The name or ordinal value of an object within a list.

 

Example

As it applies to the Actions, Attachments, Folders, Items, ItemProperties, Pages, Recipients, and UserProperties objects. 

This Visual Basic for Applications example uses the Remove method to remove all attachments from a forwarded message before sending it on to Jeff Smith.

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.ActiveInspector.CurrentItem.Forward
    Set myAttachments = myItem.Attachments
    While myAttachments.Count > 0
        myAttachments.Remove 1
    Wend
    myItem.Recipients.Add "Jeff Smith"
    myItem.Send

If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.

    Set myItem = Application.ActiveInspector.CurrentItem.Forward
    Set myAttachments = myItem.Attachments
    While myAttachments.Count > 0
        myAttachments.Remove 1
    Wend
    myItem.Recipients.Add "Jeff Smith"
    myItem.Send

As it applies to the Links, OutlookBarGroups, OutlookBarShortcuts, PropertyPages, Reminders, and Views objects.

The following example removes a View object from the Views collection.

Sub DeleteView()
'Deletes a view from the collection

    Dim olApp As Outlook.Application
    Dim objName As NameSpace
    Dim objViews As Views
    Dim objView As View
    Dim strName As String
    
    strName = "New Icon View"
    Set olApp = Outlook.Application
    Set objName = olApp.GetNamespace("MAPI")
    Set objViews = objName.GetDefaultFolder(olFolderNotes).Views
    
    For Each objView In objViews
        If objView.Name = strName Then
            objViews.Remove (strName)
        End If
    Next objView

End Sub