VBA to import birthdays into Outlook - getting error in code

rwells

New Member
Joined
Sep 21, 2016
Messages
8
Hi folks!

I found this code online to import an excel list of birthdays into Outlook & make them recurring, but I'm getting an error for one line.
Hoping someone can help.

I'm getting the following error for the line highlighted below:
Compile error: User-defined type not defined

Here's the code:


Sub ImportBirthdaysToCalendar()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow As Integer
Dim objOutlookApp As Outlook.Application
Dim objCalendar As Outlook.Folder
Dim objBirthdayEvent As Outlook.AppointmentItem
Dim objRecurrencePattern As Outlook.RecurrencePattern

'Get the specific sheet
Set objWorksheet = ThisWorkbook.Sheets(1)
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row

Set objOutlookApp = CreateObject("Outlook.Application")
Set objCalendar = objOutlookApp.Session.GetDefaultFolder(olFolderCalendar)

For nRow = 2 To nLastRow
Set objBirthdayEvent = objCalendar.Items.Add("IPM.Appointment")

'Create birthday events
With objBirthdayEvent
.Subject = objWorksheet.Range("A" & nRow) & Chr(39) & "s Birthday"
.AllDayEvent = True
.Start = objWorksheet.Range("B" & nRow)
Set objRecurrencePattern = .GetRecurrencePattern
objRecurrencePattern.RecurrenceType = olRecursYearly
.Save
End With
Next
End Sub


Any help is appreciated!
Thanks!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Tools - References... make sure the circled/highlighted option is checked (you might have a different number in your version)

1706649675547.png
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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