VBA Outlook export calendar items - Code 13 type mismatch error

zde

New Member
Joined
Jan 10, 2023
Messages
1
Office Version
  1. 365
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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
When looping through each item in your folder, check to make sure that the item is in fact an appointment item...

VBA Code:
Dim myitem As Object
Dim myapt As Outlook.AppointmentItem

sh.Range("A1:D1").Value = Array("START TIME", "END TIME", "SUBJECT", "ORGANIZER")
R = 2

For Each myitem In myfol.Items

    If TypeName(myitem) = "AppointmentItem" Then
        Set myapt = myitem
        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
    End If

Next

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top