Solved

tabulate total hours in outlook 2007 calendar

Posted on 2013-06-23
4
439 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Outlook Free & Paid Tools
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now