• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create a Series of Tasks using VBA

Slipstick Systems

› Outlook › Tasks › Create a Series of Tasks using VBA

Last reviewed on March 29, 2019     13 Comments

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.
tasks from 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:

  1. Right click on Project1 and choose Insert > Module
  2. 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.

Create a Series of Tasks using VBA was last modified: March 29th, 2019 by Diane Poremsky

Related Posts:

  • Create a Series of Tasks Leading up to an Appointment
  • Create a Task and copy to another Tasks folder
  • Creating Outlook Tasks "x" Days from a Date
  • Automatically create a task when sending a message

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
13 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

TJ Singh (@guest_201518)
September 12, 2016 2:44 pm
#201518

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  TJ Singh
September 13, 2016 12:36 am
#201529

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.

0
0
Reply
Nathan (@guest_196432)
February 12, 2016 3:24 am
#196432

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

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Nathan
February 12, 2016 10:34 am
#196445

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

0
0
Reply
Chieri Thompson (@guest_195258)
December 11, 2015 9:58 am
#195258

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.

0
0
Reply
Keith Brooks (@LotusEvangelist) (@guest_193018)
August 31, 2015 8:15 am
#193018

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.

0
0
Reply
Chris Graves (@guest_188072)
December 9, 2014 4:17 pm
#188072

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

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Chris Graves
January 7, 2015 1:41 am
#188530

You can use VBA to access BCM data - Outlook would be the one handling the work.

0
0
Reply
Chris Graves (@guest_188052)
December 8, 2014 4:03 pm
#188052

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

0
0
Reply
Ernie Davis (@guest_186991)
October 17, 2014 6:12 am
#186991

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!

1
-1
Reply
David (@guest_182471)
March 13, 2014 8:43 am
#182471

Excellent Diane. I'll have a play about with it and see what I can come up with.

Many Thanks Again.

2
-1
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 27

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Outlook: Web Bugs & Blocked HTML Images
  • How to Remove the Primary Account from Outlook
  • Adjusting Outlook's Zoom Setting in Email
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Remove a password from an Outlook *.pst File
  • Create rules that apply to an entire domain
  • Use PowerShell to get a list of Distribution Group members
  • Outlook Auto Account Setup: Encrypted Connection not available
  • This operation has been cancelled due to restrictions
  • How to Block Foreign Spam
  • Automatically Open New Outlook when Windows boots
  • Block External Content in New Outlook
  • Save Messages in New Outlook
  • Send Individual Messages when Sending Bulk Email
  • Centrally managed signatures in Office 365?
  • Create a rule to delete spam with no sender address
  • Open Outlook Folders using PowerShell or VBScript
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment