This code sample creates three new tasks based on one task, with the start and due dates of the each task in the series 2 - 5 days after the previous task.
We also have a code sample that creates tasks from a selected appointment, with each task due in the days leading up to the appointment. The code can be tweaked to create a series of tasks or appointments from an email message or other Outlook items.
If you need to create a large number of tasks or skip weekends and holidays, it will be easier to create the tasks (or appointments) in Excel and Import them into Outlook or use a utility from the Tools section below. Sample workbook
The subject in my example includes the date of the task because it makes it easier to see that it is working. Once you are satisfied with the code, you can change the subject field as necessary.
To use, select the master task (or appointment) and run the macro. To make it easier to use, assign a toolbar or QAT button to the macro.
Create a series of tasks based on one task
Updated December 7 2014 to handle a large number of tasks more efficiently. Each subsequent task is based on the task before it. For example, Task # 3 (created by the Case 2 statements) starts 4 days after the previous task, which started 2 days after the first task. With some minor tweaking, it could base the start and end times off of the original task date. See Create a Series of Tasks Leading up to an Appointment for an example.
To create more than five tasks, change the value in the i = 1 to 5 line and add additional Cases.
Public Sub CreateTasks () Dim obj As Object Dim Sel As Outlook.Selection Dim objTask As Outlook.TaskItem Dim objNewTask As Outlook.TaskItem Dim objFolder As Outlook.MAPIFolder Dim i As Long Dim sDate As Date Dim dDate As Date Dim strOriginalSubject As String, strSubject As String Set Sel = Application.ActiveExplorer.Selection If Sel.Count Then Set obj = Sel(1) Set objFolder = obj.Parent If TypeOf obj Is Outlook.TaskItem Then Set objTask = obj strOriginalSubject = objTask.Subject For i = 1 To 5 Set objNewTask = objFolder.Items.Add(olTaskItem) Select Case i ' each task is using the date of the previous task to calculate Case 1 sDate = objTask.StartDate + 2 dDate = objTask.StartDate + 5 strSubject = dDate & " " & strOriginalSubject Case 2 sDate = objTask.StartDate + 4 dDate = objTask.StartDate + 5 strSubject = dDate & " " & strOriginalSubject Case 3 sDate = objTask.StartDate + 1 dDate = objTask.StartDate + 5 strSubject = dDate & " " & strOriginalSubject Case 4 sDate = objTask.StartDate + 2 dDate = objTask.StartDate + 5 strSubject = dDate & " " & strOriginalSubject Case 5 sDate = objTask.StartDate + 3 dDate = objTask.StartDate + 5 strSubject = dDate & " " & strOriginalSubject End Select With objNewTask .Categories = objTask.Categories .Companies = objTask.Companies .ContactNames = objTask.ContactNames .Body = objTask.Body .StartDate = sDate .DueDate = dDate .Subject = strSubject .Save ' .Display End With Set objTask = objNewTask Next i End If Quit: Set objTask = Nothing Set objNewTask = Nothing Set obj = Nothing End If End Sub
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
The base for the code sample came from Journal: Create a new item based on an existing one.