How To Export Your Outlook Tasks To Excel With VBA

Compare Cost: Get 8 Free E-Commerce Design Bids
Service:
Location:
Budget:
Deadline:
Compare: Web Design Calculator | Web Design Cost Guidelines

Are you an E-Commerce Web Designer? Add a Free Listing

Whether 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.

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.

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“.

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:	empMyActiveTasks.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: emp directory, and created a header for the tasks that you’re about to insert.

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.

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
    sht.Columns("A").EntireColumn.AutoFit
    sht.Columns("B").EntireColumn.AutoFit
    sht.Columns("C").EntireColumn.AutoFit
    sht.Columns("D").EntireColumn.AutoFit
Next sht
 
exWb.Save
exWb.Close
 
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.

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!

Shutterstock


Source http://www.makeuseof.com/?p=98984
Fri, 10 Feb 2012 17:01:28 GMT
Tags:
Oceanside-Escondido E-Commerce | NOIDA E-Commerce | Bonita Springs E-Commerce | Stone Mountain E-Commerce | Ankeny E-Commerce | Coleraine E-Commerce | Rancho Cucamonga E-Commerce | Knoxville E-Commerce | Stevenage E-Commerce | Iowa Park E-Commerce |

Need E-commerce Design? Check out our member profiles:

Pleasant Prairie
AG Interactive Profile
AG Interactive

AG-INTERACTIVE is a Kenosha Web Design, Web Development, E-Commerce design firm for those have budgets in mind. Let us help you reach your goal with affordable web design.

Pleasant Prairie, Wisconsin US
Austin
Clarity Ventures, Inc. Profile
Clarity Ventures, Inc.

Clarity Ventures is an Austin, TX based consulting company committed to building innovative web based solutions for our clients (e-commerce, content management, design, and SEO / marketing).

Austin, Texas US
Coleraine
White Ivy Design & Marketing Minnesota Profile
White Ivy Design & Marketing Minnesota

White Ivy Design & Marketing: graphic designers & web programmers in Minnesota, transforming your ideas into powerful communications... Grand Rapids, Hibbing, Brainerd, Duluth, all of MN.

Coleraine, Minnesota US
Oakville
E Avenue Profile
E Avenue

E Avenue is an interactive marketing agency. We specialize in e-commerce websites & have over 15 years experience in the affiliate marketing space as designers, programmers, marketers and affiliates.

Oakville, Ontario CA
Mantua
StudioKraft Creative Web Services Profile
StudioKraft Creative Web Services

Offering professional e-commerce design and development services since 2001, StudioKraft welcomes the opportunity to help you sell online. Specializing in OSCommerce customized installs.

Mantua, New Jersey US
Scottsbluff
Hale Multimedia LLC Profile
Hale Multimedia LLC

In Business as a full service website company since 1996. Our Easy-Update technology makes it very simple for our clients to update their own website. Call for a free review of your project today!

Scottsbluff, Nebraska US
Miami
Indianapolis
Arealbiker.com Profile
Arealbiker.com

We specialize in creating custom Social Networks for the Motorcycle & related Industry. If you have a boring website and want to go Social then contact us to bring your site ALIVE.

Indianapolis, Indiana US



Get Free Logo Design Quotes






Ecommerce Links: January 2012

Before we dive into the links there 8217 s still time to register for Conversion Conference and Af



40 Inspiring Vector Portrait Examples

A vector portrait is a computer generated work of art made up of lines filled with blocks of color



Come & Work For Us Here At MakeUseOf – We Have Cookies!

MakeUseOf is always on the hunt for fresh new talent who have the skills experience and energy to t



Automate Repetitive Forms And Registrations In A Snap With Autofill Forms [Firefox]

If there s any downside to working online it d have to be the repetitive tasks that hit you in the



Make Skim Your Ultimate Reading & Study Tool For PDF Files [Mac]

Though Apple s PDF reader and image correction application Preview is a highly used default progra



6 Apps That Provide Everything A Skateboarder Needs [iOS]

Did you know there is a ton of apps on your iPhone tailor made for skateboarders Well you do now I



Just Gestures Lets You Use Mouse Gestures To Control Windows

Keyboard shortcuts are a well known strategy to cut a few corners and avoid navigating menus while w




Design Leads

Article Tags
E-commerce Design Articles
Web Apps & Internet (374)
News (291)
Web Apps (129)
Inspiration (128)
Music (119)
iPhone / iPad / iPod (116)
cool web apps (108)
Google Android (101)
Mobile Tips (100)
Announcements (99)
deals (88)
Games & Gaming Tips (84)
Tech Deals (82)
Opinion & Polls (76)
Cool Software Apps (76)
Social Media (66)
iOS (66)
Browser Tips & Tricks (66)
iPhone Apps (59)
Freebies (58)
geeky fun (58)
Photography (58)
iphone (55)
Google (53)
troubleshoot (53)
android (52)
Photoshop (52)
Graphics (51)
facebook (50)
How-To Articles (50)

Friends:
E-Commerce Website Pricing
Web Design Quote
Website Design
Graphic Designers


E-commerce Design Valid HTML 4.0 Transitional Valid CSS!