I created a code for exporting calendar appointments from outlook. It runs perfectly for me, however we get code 13 error on one of my collegue's computer who is supposed to use the macro. The error is at the "Next" line, and she uses the same outlook version as me.
Can anyone please help me what could cause the issue? Thanks in advance!
Sub outlook_calendaritemsexport()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("CalendarExport")
Dim o As Outlook.Application, R As Long
Set o = New Outlook.Application
Dim ons As Outlook.Namespace
Set ons = o.GetNamespace("MAPI")
Dim myfol As Outlook.Folder
Set myfol = ons.GetDefaultFolder(olFolderCalendar)
Dim myapt As Outlook.AppointmentItem
sh.Range("A1:D1").Value = Array("START TIME", "END TIME", "SUBJECT", "ORGANIZER")
R = 2
For Each myapt In myfol.Items
sh.Cells(R, 1).Value = myapt.Start
sh.Cells(R, 2).Value = myapt.End
sh.Cells(R, 3).Value = myapt.Subject
sh.Cells(R, 4).Value = myapt.Organizer
R = R + 1
Next
Set o = Nothing
Set ons = Nothing
Set myfol = Nothing
Set myapt = Nothing
Call CopyDataBasedOnStatusCondtion
sh.Range("A9:I" & Rows.Count).Interior.Color = xlNone
End Sub
Can anyone please help me what could cause the issue? Thanks in advance!
Sub outlook_calendaritemsexport()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("CalendarExport")
Dim o As Outlook.Application, R As Long
Set o = New Outlook.Application
Dim ons As Outlook.Namespace
Set ons = o.GetNamespace("MAPI")
Dim myfol As Outlook.Folder
Set myfol = ons.GetDefaultFolder(olFolderCalendar)
Dim myapt As Outlook.AppointmentItem
sh.Range("A1:D1").Value = Array("START TIME", "END TIME", "SUBJECT", "ORGANIZER")
R = 2
For Each myapt In myfol.Items
sh.Cells(R, 1).Value = myapt.Start
sh.Cells(R, 2).Value = myapt.End
sh.Cells(R, 3).Value = myapt.Subject
sh.Cells(R, 4).Value = myapt.Organizer
R = R + 1
Next
Set o = Nothing
Set ons = Nothing
Set myfol = Nothing
Set myapt = Nothing
Call CopyDataBasedOnStatusCondtion
sh.Range("A9:I" & Rows.Count).Interior.Color = xlNone
End Sub