I'm using the code below but have an issue with this line:
Code:
myArr(4, NextRow) = olApt.AllDayEvent
Im using this property basaed on the information here: https://docs.microsoft.com/en-us/off...ent-properties
It will always return N/A. I need to determin if its an all day event i am exporting so I can take 1 day off the end date. (all day events finish at midnight and the system will count this as two days.).
would anyone have any ideas for this?
Code:
Sub Workbook_Open()
On Error GoTo ErrHand:
Application.ScreenUpdating = False
'This is an enumeration value in context of getDefaultSharedFolder
Const olFolderCalendar As Byte = 9
Dim olapp As Object: Set olapp = CreateObject("Outlook.Application")
Dim olNS As Object: Set olNS = olapp.GetNamespace("MAPI")
Dim olfolder As Object
Dim olApt As Object: Set olNS = olapp.GetNamespace("MAPI")
Dim objOwner As Object: Set objOwner = olNS.CreateRecipient("andrew.holme@ramptec.co.uk")
Dim NextRow As Long
Dim olmiarr As Object
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
''''''''''''''''test code'''''''''''''''''
''''''''''''''''test code'''''''''''''''''
objOwner.Resolve
If objOwner.Resolved Then
Set olfolder = olNS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
ws.Range("A1:D1").Value2 = Array("Subject", "Start", "End", "Category", "All_Day_Event")
'Ensure there at least 1 item to continue
If olfolder.items.Count = 0 Then Exit Sub
'Create an array large enough to hold all records
Dim myArr() As Variant: ReDim myArr(0 To 3, 0 To olfolder.items.Count - 1)
'Add the records to an array
'Add this error skip, as I found some of my calendar items don't have all properties e.g. a start time
On Error Resume Next
For Each olApt In olfolder.items
myArr(0, NextRow) = olApt.Subject
myArr(1, NextRow) = olApt.Start
myArr(2, NextRow) = olApt.End
myArr(3, NextRow) = olApt.Categories
myArr(4, NextRow) = olApt.AllDayEvent
NextRow = NextRow + 1
Next
On Error GoTo 0
'Write all records to a worksheet from an array, this is much faster
ws.Range("A2:E" & NextRow + 1).Value = WorksheetFunction.Transpose(myArr)
'AutoFit
ws.Columns.AutoFit
cleanExit:
Application.ScreenUpdating = True
Exit Sub
ErrHand:
'Add error handler
Resume cleanExit
End Sub