How Do You Write VBA Code To Access Calendar Data In Microsoft Outlook?
• In this example, we will access a calendar named “Cox”. It is located in the “My Calendars” folder of my Outlook application. • The code is as follows: • Public Sub ReadCalendar(name As String, outputFile as String) • Set myOlApp = CreateObject(“Outlook.Application”) • Set myNameSpace = myOlApp.GetNamespace(“MAPI”) • Set MyFolder = myNameSpace.GetDefaultFolder(olFolderCalendar) • Set myNewFolder = MyFolder.Folders(name) • Dim oItems As Outlook.Items • Set oItems = myNewFolder.Items • oItems.Sort “[Start]” • Dim ret As String • For Each oAppt In oItems • ret = ret + oAppt.Subject • ret = ret + Chr(9) + Str$(DatePart(“m”, oAppt.Start)) + “/” + Str$(DatePart(“d”, oAppt.Start)) + “-” • ret = ret + Str$(DatePart(“m”, oAppt.End)) + “/” + Str$(DatePart(“d”, oAppt.End)) + “/” + Str$(DatePart(“yyyy”, oAppt.End)) • ret = ret + Chr(13) + Chr(10) • Next • MsgBox (ret) • Open outputFile For Output As #1 • For Each oAppt In oItems • ret = ret + oAppt.Subject • ret = ret + Chr(9) + Str$(DatePart(“m