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.
More Information
Create a series of tasks leading up to an appointment
The base for the code sample came from Journal: Create a new item based on an existing one.
Hello, I am new to this VBA coding. I am getting this error saying " Compile Error: User-defined type not defined" when I run the code.
I already changed the references and selected .DAO files.
Does anyone know what mistake I am making.
it means you are calling a procedure that is not referenced. I'm not sure how .dao files fit into this - this is an Outlook macro.
Did you edit the macro? it might help if you post your macro.
This is a great macro. How would I assign different categories to the tasks as they are created?
For example if i wanted task 1 to be in Category A, Task 2 Category B Task 3 Category A and so on.
Thannks
At the top of the macro, add a line to dim strCategory as string
In each case statement, add a line to set a category string
Case 1
sDate = objTask.StartDate + 2
dDate = objTask.StartDate + 5
strSubject = dDate & " " & strOriginalSubject
strCategory = "Category A"
Set the string as the category:
With objNewTask
.Categories = strCategory
What if you need to distribute tasks from another account? I'm the owner of my "personal" account and the other is shared among-st myself & coworkers (non of us are the owners of this account). Is it possible to send out tasks via VBA from a secondary account? I typically manually send out 4 tasks every morning from the secondary shared account.
How do you verify if the tasks have already been created? We have 2 different people doing updates but if they are not in synch we end up with duplicates. I want to use the subject as a reference as subjects are unique.
Hi Diane,
Is it possible in principle to use VBA in BCM (Outlook) 2010 to automate the emailing of a series of different html emails on a schedule?
Best regards,
Chris
You can use VBA to access BCM data - Outlook would be the one handling the work.
Hi Diane,
I am researching whether or not to use BCM 2013 four small business' CRM. Our main concern is to be able to automate elements of our sales process. In particular, we would like to be able to create a lead 'template' where each new lead is put into a process where every certain number of days a new html email will be sent to them. Is it possible to program this is VBA? I thought this was a good place for this question because the code you describe here pertains to scheduling events.
Beswt regards,
Chris Graves
I would paste the code I ended up with here as well... but the code above is so complete and fluent, there were very few changes to the logic required. A little mild cleanup + the required customization and it was magic. Thank you all for the contribution!
Excellent Diane. I'll have a play about with it and see what I can come up with.
Many Thanks Again.