Sub DisplayYearlyCalendar() 'copyright Nick Roemer 'http://niveauverleih.blogspot.com/ 'version 1.9, 22 Jan 2009 'copy and paste this code into your Outlook Visual Basic Editor 'Therefore just press Alt+F11 in your Outlook 'Right click on 'Modules' 'choose 'insert/module' 'paste the code in the big white window on the right hand side 'Run it from Outlook via Tools/Macro/Macros/DisplayYearlyCalendar 'this macro will display your Outlook appointments over a period of several months 'or an empty calendar to print out 'the output is an html file that is displayed with Internet Explorer '------------------------------------------------------------------- 'list here the categories that you want to hide 'e.g. arrExcludeCategories = Array("@home", "Personal") arrExcludeCategories = Array() 'Set this to TRUE if you want to display private appointments Const blShowPrivateAppointments = True 'Set this to FALSE if you want the rows to be the day of month (1,2, ...31) iso. the days of the week (Mo.. Fri) Const blAlignWeekDays = True 'Set this to TRUE if you want to display AllDayEvents only blAllDayEventsOnly = False 'colors from http://web.njit.edu/~kevin/rgb.txt.html Const wheat_light = "#EED8AE" Const wheat_dark = "#CDBA96" Const seashell = "#EEE5DE" Const silver = "#C0C0C0" Const forwrite = 2 Set objShell = CreateObject("WScript.Shell") strTempFolder = objShell.ExpandEnvironmentStrings("%TEMP%") strHtmlFile = strTempFolder & "\YearlyCalendar.html" StartMonth = InputBox("Start Month", "Start Month", Month(Date)) If StartMonth = "" Then Exit Sub StartMonth = CInt(StartMonth) EndMonth = InputBox("End Month", "End Month", StartMonth - 1) If EndMonth = "" Then Exit Sub EndMonth = CInt(EndMonth) If EndMonth < StartMonth Then NbMonths = EndMonth - StartMonth + 13 EndMonth = EndMonth + 12 Else NbMonths = EndMonth - StartMonth + 1 End If strEmptyCalendar = MsgBox("Empty Calendar?", vbYesNo + vbDefaultButton2) 'Create Table: 1 Header Row ' 7 days x 5 weeks = 35 day rows ' 1 Header column ' 1 column for each month Contents = "
| " & "Month" & " | " 'First Row intYear = Year(Date) nextYear = intYear + 1 For i = StartMonth To EndMonth MonthInNumbers = i If i > 12 Then MonthInNumbers = i - 12 intYear = nextYear End If Contents = Contents & vbCrLf & "" & MonthName(MonthInNumbers) & " " & intYear & " | " Next Contents = Contents & vbCrLf & "|
|---|---|---|
| " & WeekdayName(intWeekday, False, vbMonday) & " | " Else Contents = Contents & vbCrLf & "" & RowCount & " | " End If intYear = Year(Date) 'Month columns For i = StartMonth To EndMonth MonthInNumbers = i If i > 12 Then MonthInNumbers = i - 12 intYear = nextYear End If StrMonthStartsOnA = 1 If blAlignWeekDays Then 'e.g. if the first of the month falls on a Friday ' we need to put some grey cells before the month begins StrMonthStartsOnA = Weekday(CDate("1 " & MonthName(MonthInNumbers) & ", " & intYear), vbMonday) End If intDayOfMonth = 0 If RowCount >= StrMonthStartsOnA Then intDayOfMonth = RowCount - StrMonthStartsOnA + 1 End If 'calculate date for current cell strDate = "" If intDayOfMonth > 0 Then On Error Resume Next strDate = CDate(CStr(intDayOfMonth) & " " & MonthName(MonthInNumbers) & ", " & CStr(intYear)) On Error GoTo 0 End If 'color weekends intRealWeekday = intWeekday If Not blAlignWeekDays Then On Error Resume Next intRealWeekday = Weekday(strDate) 'Weekday(DateAdd("d", -1, strDate)) On Error GoTo 0 End If bgcolor = "#FFFFFF" Select Case intRealWeekday Case 7 bgcolor = wheat_light Case 1 bgcolor = wheat_dark End Select If blAlignWeekDays Then bgcolor = "#FFFFFF" Select Case intRealWeekday Case 6 bgcolor = wheat_light Case 7 bgcolor = wheat_dark End Select End If 'grey out empty cells dispDate = "" If strDate = "" Then bgcolor = silver ElseIf blAlignWeekDays Then dispDate = "" & Day(strDate) & " " & MonthName(MonthInNumbers, True) & "" Else 'if blAlignWeekDays = False dispDate = "" & Day(strDate) & " " & WeekdayName(intRealWeekday, True, vbSunday) & "" End If 'display date Contents = Contents & vbCrLf & "" & dispDate & " "
'display appointments
If strEmptyCalendar = vbNo Then
strRestriction = "(([Start] >= '" & strDate & " 12:00 am' AND [Start] <= '" & strDate & " 11:59 pm')"
strRestriction = strRestriction & " OR ([End] > '" & strDate & " 12:00 am' AND [End] <= '" & strDate & " 11:59 pm')"
strRestriction = strRestriction & " OR ([Start] < '" & strDate & " 12:00 am' AND [End] > '" & strDate & " 11:59 pm'))"
strRestriction = strRestriction & " AND [Duration] > 0"
If strDate = "" Then strRestriction = "[Start] = 1" 'no result
Set myRestrictItems = MyFolder.Restrict(strRestriction)
myRestrictItems.Sort "[Start]"
'Contents = Contents & vbCrLf & myRestrictItems.Count & " " For Each myitem In myRestrictItems blDisplay = True 'check if this appointment is in a category that we want to hide For Each strCat2Exclude In arrExcludeCategories If InStr(myitem.Categories, strCat2Exclude) Then blDisplay = False Next 'check if this is a private appointment If blShowPrivateAppointments = False And myitem.Sensitivity = 2 Then blDisplay = False blIsAllDayEvent = myitem.AllDayEvent If blAllDayEventsOnly And Not blIsAllDayEvent Then blDisplay = False 'Display the appointment If blDisplay Then strTime = "" If Not blIsAllDayEvent Then strTime = " " & Hour(myitem.Start) & "h" If Minute(myitem.Start) <> 0 Then strTime = strTime & Minute(myitem.Start) strTime = strTime & " " End If Contents = Contents & strTime & "" & myitem.Subject & vbCrLf & "" End If Next Else Contents = Contents & " " End If Contents = Contents & vbCrLf & " | "
Next
Contents = Contents & vbCrLf & "