To remove an Opportunity object programmatically, first select the object and then call the Delete method. The following C# and Visual Basic for Applications (VBA) examples show how to delete a new Opportunity object.
else
{
Console.WriteLine("Opportunity Not Found");
}
}
Sub DeleteOpportunity()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolders As Outlook.Folders
Dim bcmRootFolder As Outlook.Folder
Dim bcmOppFolder As Outlook.Folder
Dim existOpportunity As Outlook.TaskItem
Set olApp = CreateObject("Outlook.Application")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolders = objNS.Session.Folders
Set bcmRootFolder = olFolders("Business Contact Manager")
Set bcmOppFolder = bcmRootFolder.Folders("Opportunities")
Set existOpportunity = bcmOppFolder.Items.Find("[Subject] = 'Opportunity For Wide World Importers to enter into Retail Field'")
If Not TypeName(existOpportunity) = "Nothing" Then
existOpportunity.Delete
Else
MsgBox ("Failed to find the Opportuntiy with Subject Opportunity For John Smith to take over the Spring Sales")
End If
Set existOpportunity = Nothing
Set bcmOppFolder = Nothing
Set bcmRootFolder = Nothing
Set olFolders = Nothing
Set objNS = Nothing
Set olApp = Nothing