Share via


Delete a Project Task

To remove a Project Task object, 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 Project Task object.

C#

  private void DeleteProjectTask()
{ 

   Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
   Outlook.Application olApp = (Outlook.Application)_app;
   Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
   Outlook.Folders folders = olNameSpace.Session.Folders;
   Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"];
   //first create a BCM project
   Outlook.Folder projects = (Outlook.Folder)bcmRootFolder.Folders["Business Projects"]; 

   Outlook.Folder projectTasksFolder = (Outlook.Folder)projects.Folders["Project Tasks"]; 

   string strQuery = "[Subject] = 'Task 1 for Sales Project with Wide World Importers'"; 

   Outlook.TaskItem projectTaskItem = (Outlook.TaskItem)projectTasksFolder.Items.Find(strQuery);
   if (projectTaskItem != null)
   { 
      projectTaskItem.Delete(); 
   } 

   else
   { 
      Console.WriteLine("Project Task not found"); 
   }
   
   Console.ReadLine(); 

}


VBA

  Sub DeleteProjectTask() 

   Dim olApp As Outlook.Application
   Dim objNS As Outlook.NameSpace
   Dim olFolders As Outlook.Folders
   Dim bcmRootFolder As Outlook.Folder
   Dim bcmProjFolder As Outlook.Folder
   Dim bcmProjectTasksFolder As Outlook.Folder
   Dim existProjectTask 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 bcmProjFolder = bcmRootFolder.Folders("Business Projects")
   Set bcmProjectTasksFolder = bcmProjFolder.Folders("Project Tasks") 

   Set existProjectTask = bcmProjectTasksFolder.Items.Find("[Subject] = 'Task 1 for Sales Project with Wide World Importers'")
   If Not TypeName(existProjectTask) = "Nothing" Then 

      existProjectTask.Delete 

   Else 

      MsgBox ("Project Task not found") 

   End If 

   Set existProjectTask = Nothing
   Set bcmProjFolder = Nothing
   Set bcmProjectTasksFolder = Nothing
   Set bcmRootFolder = Nothing
   Set olFolders = Nothing
   Set objNS = Nothing
   Set olApp = Nothing 

End Sub 


See Also

Create a Project Task | Select a Project Task | Edit a Project Task | 2007 Office System: Updated Developer Content