Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Macro in Outlok 2010 to add sum of booked time this week and per week for the following 3 weeks

Posted on 2015-01-20
Medium Priority
Last Modified: 2015-05-16
Dear expert,

Interested in a macro in outlook 2010 which provide the sum per week of booked time  in my calendar for this week and the following 3 weeks.

Question by:easycapital
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 76

Expert Comment

by:David Lee
ID: 40561711
Hi, JP.

Do you want this to run using fixed weeks (i.e. Sunday to Saturday) or do you want the week to start on the day the macro is run (e.g. if I run it today then each week would start on Wednesday and end on Tuesday)?  Also, what do you want to do with the sums once they're calculated (e.g. display them on screen, write them to a file)?

Author Comment

ID: 40567320
Dear BlueDevilFan,

1. Monday to Sunday.
2. Write to an excel file.

Thank you.


Author Comment

ID: 40567321
Outlook calendar shows the week number.
LVL 20

Accepted Solution

ltlbearand3 earned 1500 total points
ID: 40597681
I have been watching this question to see what kind of solution BlueDevilFan would come up with as I usually learn good things from his posts.  However, since it has been a few weeks I will post some code to hopefully get you started.  This code can run from within Excel and will find all calendar items in the default calendar for three weeks starting with the Monday of the current week and put the total in cell A1 in a Excel Workbook.

' ExpertExchange Question ID 28600516
' Expert: ltlbearand3 []

Public Sub BookedTime()
    ' Required References:
    Dim objCalendarFldr As Outlook.Folder
    Dim objAptItems As Outlook.Items
    Dim objFilteredApt As Outlook.Items
    Dim objAppt As Outlook.AppointmentItem
    Dim dteStart As Date
    Dim lngTotalTime As Long
    Dim objExcel As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Set objCalendarFldr = Session.GetDefaultFolder(olFolderCalendar)
    Set objAptItems = objCalendarFldr.Items
    'Find a Start Date of Monday
    dteStart = DateAdd("d", -Weekday(Date, vbMonday), Date)
    ' Filter the List
    With objAptItems
        .IncludeRecurrences = True
        .Sort "[Start]"
    End With
    Set objFilteredApt = objAptItems.Restrict("[Start] >= '" & Format$(dteStart, "mm/dd/yyyy hh:mm AMPM") & "' AND [End] <= '" & _
        Format$(DateAdd("d", 21, dteStart), "mm/dd/yyyy hh:mm AMPM") & "'")
    ' Calculate Total Time
    For Each objAppt In objFilteredApt
        lngTotalTime = lngTotalTime + objAppt.Duration

    ' Write to Excel
    Set objExcel = New Excel.Application
    objExcel.Visible = False
    Set objWorkbook = objExcel.Workbooks.Add
    Set objWorksheet = objWorkbook.Worksheets.Add
    objWorksheet.Range("A1").Value = lngTotalTime
    objWorkbook.SaveAs "c:\EE_Q28600516.xlsx"
    ' Clean up
    Set objCalendarFldr = Nothing
    Set objAptItems = Nothing
    Set objFilteredApt = Nothing
    Set objAppt = Nothing
    Set objWorksheet = Nothing
    Set objWorkbook = Nothing
    Set objExcel = Nothing

End Sub

Open in new window


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question