VBA to import birthdays into Outlook - getting error in code

rwells

New Member
Joined
Sep 21, 2016
Messages
10
Office Version
  1. 365
Platform
  1. Windows
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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Tools - References... make sure the circled/highlighted option is checked (you might have a different number in your version)

1706649675547.png
 
Upvote 0
Solution
Oy - I had that checked, but must have double-clicked it and unchecked it.
Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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