Solved

tabulate total hours in outlook 2007 calendar

Posted on 2013-06-23
4
443 Views
Last Modified: 2013-09-13
not sure if this can be done in outlook 2007.  we have a list of appointments in the calendar for days / weeks, is there a way to tabulate how many hours incurred for similiar appointments for a day or whole week?
0
Comment
Question by:grnow
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39270759
Hi, grnow.

It's possible with a macro.  Do you want to see the result on screen (i.e. a dialog-box) or do you want it written to a file?
0
 

Author Comment

by:grnow
ID: 39273802
Hi, if can, good to be able to export to excel. thanks.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39274317
This macro should get the job done.  Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Press ALT+F11 to open the Visual Basic editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

Sub TabulateHours()
    Const MACRO_NAME = "Tabulate Hours"
    Dim datBeg As Date, _
        datEnd As Date, _
        olkCal As Outlook.Items, _
        olkApt As Outlook.AppointmentItem, _
        objDic As Object, _
        excApp As Object, _
        excWkb As Object, _
        excWks As Object, _
        arrKey As Variant, _
        arrVal As Variant, _
        intIdx As Integer, _
        lngRow As Long
    datBeg = InputBox("Enter a beginning date/time.", MACRO_NAME, Now)
    If Application.ActiveExplorer.CurrentFolder.DefaultItemType = olAppointmentItem Then
        If IsDate(datBeg) Then
            datEnd = InputBox("Entering an ending date/time.", MACRO_NAME, DateAdd("d", 7, datBeg))
            If IsDate(datEnd) Then
                Set objDic = CreateObject("Scripting.Dictionary")
                Set olkCal = Application.ActiveExplorer.CurrentFolder.Items
                olkCal.Sort "[Start]"
                olkCal.IncludeRecurrences = True
                Set olkCal = olkCal.Restrict("[Start] >= '" & Format(datBeg, "ddddd h:nn AMPM") & "' AND [End] <= '" & Format(datEnd, "ddddd h:nn AMPM") & "'")
                For Each olkApt In olkCal
                    If Not olkApt.AllDayEvent Then
                        If objDic.Exists(olkApt.Subject) Then
                            objDic.Item(olkApt.Subject) = objDic.Item(olkApt.Subject) + olkApt.Duration
                        Else
                            objDic.Add olkApt.Subject, olkApt.Duration
                        End If
                    End If
                Next
                Set excApp = CreateObject("Excel.Application")
                Set excWkb = excApp.Workbooks.Add
                Set excWks = excWkb.Worksheets(1)
                With excWks
                    .Cells(1, 1) = "Subject"
                    .Cells(1, 2) = "Hours"
                End With
                lngRow = 2
                arrKey = objDic.Keys
                arrVal = objDic.Items
                For intIdx = LBound(arrKey) To UBound(arrKey)
                    excWks.Cells(lngRow, 1) = arrKey(intIdx)
                    excWks.Cells(lngRow, 2) = arrVal(intIdx) / 60
                    lngRow = lngRow + 1
                Next
                excWks.Columns("A:B").AutoFit
                excApp.Visible = True
            Else
                MsgBox "Operation cancelled.  You must enter a valid date/time.  Please try again.", vbCritical + vbOKOnly, MACRO_NAME
            End If
        Else
            MsgBox "Operation cancelled.  You must enter a valid date/time.  Please try again.", vbCritical + vbOKOnly, MACRO_NAME
        End If
    Else
        MsgBox "Operation cancelled.  You must select a calendar folder.  Please try again.", vbCritical + vbOKOnly, MACRO_NAME
    End If
    Set excWks = Nothing
    Set excWkb = Nothing
    Set excApp = Nothing
    Set objDic = Nothing
    Set olkApt = Nothing
    Set olkCal = Nothing
End Sub

Open in new window


To use this macro

1.  Open Outlook
2.  Select a calendar
3.  Run the macro
4.  Enter a beginning date/time
5.  Enter an ending date/time

The macro will loop through the appointments that fall within the date/time range you entered in steps 4 and 5 summing the appointment duration based on the subject.  Here's an example.   Say that there were 5 appointments in the specified date/time range with a subject of "Sales Meeting".  Each of these appointments was 30 minutes long.  There were also 2 appointments with a subject of "Project X Planning".  One was 60 minutes long and the other 30 minutes long.  Finally, there was a single appointment with a subject of "Weekly Staff Meeting" that was 60 minutes long.  The macro would output

Subject                           Hours
Sales Meeting                      2.5
Project X Planning               1.5
Weekly Staff Meeting          1.0
0
 

Author Comment

by:grnow
ID: 39314834
thanks, will try it soon and let you know
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

777 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