Remove Method

Microsoft Outlook Visual Basic

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.

ShowRemove 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

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

This Visual Basic for Applications (VBA) example uses the Remove method to remove all attachments from a forwarded message before sending it on to Dan Wilson. Before running this example, replace 'Dan Wilson' with a valid recipient name.

Sub RemoveAttachmentBeforeForwarding()
    Dim myolApp As Outlook.Application
    Dim myinspector As Outlook.Inspector
    Dim myItem As Outlook.MailItem
    Dim myattachments As Outlook.Attachments
    Set myolApp = CreateObject("Outlook.Application")
    Set myinspector = myolApp.ActiveInspector
    If Not TypeName(myinspector) = "Nothing" Then
        Set myItem = myinspector.CurrentItem.Forward
        Set myattachments = myItem.Attachments
        While myattachments.Count > 0
               myattachments.Remove 1
        Wend
        myItem.Display
        myItem.Recipients.Add "Dan Wilson"
        myItem.Send
    Else
        MsgBox "There is no active inspector."
    End If
End Sub
		

ShowAs 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 Outlook.NameSpace
    Dim objViews As Outlook.Views
    Dim objView As Outlook.View
    Dim strName As String
    
    strName = "New Icon View"
    Set olApp = New 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