How To Export Your Outlook Tasks To Excel With VBA

Ads by Google

export outlook tasks to excelWhether or not you are a fan of Microsoft, one good thing that can be said about MS Office products, at least, is how easy it is to integrate each of them with one another.

Just think of the power that comes from having incoming emails automatically generating new tasks or new calendar appointments, or having a completed task automatically email your boss with the updated status report from the task description.

If you do it right, you can cut your entire day’s workload by a boatload just by automating things in an intelligent and efficient way.

If you follow my writing here, then you know that in the past I’ve covered things like integrating web browser features into Excel, automatically maximizing application windows, or automating chart updates in Excel.

Well, in this article I’m going to cover another automation task – actually one that I’ve used often more recently – to automatically update an Excel spreadsheet with all of your remaining active Outlook tasks at the end of the day.

Feeding Outlook Tasks To An Excel Spreadsheet

There are a lot of reasons you may want to do this. Maybe you want to track your unfinished tasks on a daily basis in a format that you can quickly mail off to someone (not so easy to do with Outlook tasks). Or maybe it’ll become part of a larger report that you’ll be typing up in Word.

Ads by Google

Whatever the case may be, the ability to capture and output uncompleted Outlook task information is a useful thing.

For this example, here’s my sample Outlook task list with 5 remaining tasks that I still haven’t completed yet.

export outlook tasks to excel

Everything we’re going to do here, is in VBA. In Outlook, you get to the VBA editor by clicking on “Tools“, then “Macro” and then choosing the “Visual Basic Editor“.

export outlook tasks to csv

The code that you’re going to use to capture your task list and export it to Excel is actually not quite as complicated as you might think. The first step is to plug into both Outlook objects and Excel objects by creating the necessary variable definitions. Then, using the workbook object you’ve created, start off by creating the header in your spreadsheet.

Dim strReport As String
  Dim olnameSpace As Outlook.NameSpace
  Dim taskFolder As Outlook.MAPIFolder
  Dim tasks As Outlook.Items
  Dim tsk As Outlook.TaskItem
  Dim objExcel As New Excel.Application
  Dim exWb As Excel.Workbook
  Dim sht As Excel.Worksheet

  Dim strMyName As String
  Dim x As Integer
  Dim y As Integer

  Set exWb = objExcel.Workbooks.Open("c:\temp\MyActiveTasks.xls")

'  exWb.Sheets(strMyName).Delete
'  exWb.Sheets.Add (strMyName)

  Set olnameSpace = Application.GetNamespace("MAPI")
  Set taskFolder = olnameSpace.GetDefaultFolder(olFolderTasks)

  Set tasks = taskFolder.Items

  strReport = ""

  'Create Header
  exWb.Sheets("Sheet1").Cells(1, 1) = "Subject"
  exWb.Sheets("Sheet1").Cells(1, 2) = "Due Date"
  exWb.Sheets("Sheet1").Cells(1, 3) = "Percent Complete"
  exWb.Sheets("Sheet1").Cells(1, 4) = "Status"

So, here’s what the new spreadsheet looks like. Your Outlook app just created a new Excel file called “MyActiveTasks.xls” in the C:\temp directory, and created a header for the tasks that you’re about to insert.

export outlook tasks to csv

So, now it’s time to extract your tasks and insert them into the Excel file. I use a “y” variable starting at two in order to make sure the first row that’s used isn’t the first, because I don’t want to overwrite the header.

y = 2

  For x = 1 To tasks.Count

       Set tsk = tasks.Item(x)

       'strReport = strReport + tsk.Subject + "; "

       'Fill in Data
       If Not tsk.Complete Then

        exWb.Sheets("Ryan").Cells(y, 1) = tsk.Subject
        exWb.Sheets("Ryan").Cells(y, 2) = tsk.DueDate
        exWb.Sheets("Ryan").Cells(y, 3) = tsk.PercentComplete
        exWb.Sheets("Ryan").Cells(y, 4) = tsk.Status
        y = y + 1

       End If

  Next x

What this script does is searches through your entire list of task items in Outlook, checks to see whether the item is completed yet, and if it isn’t, then it inserts that task information into 4 cells of the spreadsheet. If you wanted to, you could insert more information. Just explore what task information is available by typing “tsk.” and then browsing through the list of properties that pop up.

Now here’s what the sheet looks like.

export outlook tasks to csv

Being a bit of a perfectionist, there’s still a problem. Notice how column A clipped the last task subject?” I don’t like that. So let’s add a little bit more code to autofit all columns in the Excel table.

'Autofit all column widths

For Each sht In ActiveWorkbook.Worksheets
Next sht


Set exWb = Nothing

The Save and Close methods in those last few lines will save the sheet and close it so that it doesn’t remain locked by the application, otherwise it would be difficult to open the Excel file until you closed Outlook.

So, now here’s what the finished spreadsheet looks like.

export outlook tasks to excel

When do you set the script to run? Well, I set it up to run on the “Application.Close()” event, which runs when you exit Outlook at the end of the day. This will make outlook produce the Excel spreadsheet report at the end of the day, all on its own.

Can you think of any other cool uses for this technique? Maybe automatically firing off an email with the list of tasks, or outputting them to an HTML file and FTPing it to your web server?

With a little creativity, it’s amazing what you can pull off with a bit of scripting automation. Share your own thoughts and ideas in the comments section below!


Join live MakeUseOf Groups on Grouvi App Join live Groups on Grouvi
Windows Hacks & Customization
Windows Hacks & Customization
97 Members
Learn New Skills
Learn New Skills
91 Members
Self Improvement
Self Improvement
90 Members
87 Members
Productivity Apps & Tips
Productivity Apps & Tips
80 Members
Best Windows Software
Best Windows Software
59 Members
Windows Troubleshooting
Windows Troubleshooting
59 Members
Microsoft Office Help
Microsoft Office Help
35 Members
Windows Firewalls & Antivirus
Windows Firewalls & Antivirus
19 Members
Ads by Google
Comments (12)
  • Clive

    Ryan, is it possible to this the other way round? , i.e. I have a spreadsheet with a bunch of tasks for a number of different people and I’d like to be able to assign these tasks to their individual outlook to-do lists. Any idea how to achieve that?

  • Asif

    Can we use this in OWA or any other way to track the uncompleted items

  • Michael

    New to VBA design….can’t get this to run… you have a cookbook version?

  • Jason

    Is this limited to uncompleted tasks?
    Can I export all tasks regardless of whether they are completed or not?

    • Ryan Dube

      No – you can see all of the available task parameters you can use by typing “tsk.” and checking the dropdown list.

      I’m referring to the section of code that goes: “If Not tsk.Complete Then”

      The “tsk” object as defined in the code will show you all of the available task parameters you can check against.

      Hope that helps.

  • Brandon Colon

    I am getting an ‘Out of Range’ runtime error that is referring to this part of the code –
    exWb.Sheets(“Ryan”).Cells(y, 1) = tsk.Subject. Been troubleshooting for a while, but can’t seem to come up with anything…

    • Ryan Dube

      Hi Brandon – you need to change “Ryan” to the name of the sheet in your workbook.

Load 10 more
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.