Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

tabulate total hours in outlook 2007 calendar

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
grnow
Asked:
grnow
  • 2
  • 2
1 Solution
 
David LeeCommented:
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
 
grnowAuthor Commented:
Hi, if can, good to be able to export to excel. thanks.
0
 
David LeeCommented:
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
 
grnowAuthor Commented:
thanks, will try it soon and let you know
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now