+ Reply to Thread
Results 1 to 2 of 2

VBA to import birthdays into Outlook - getting error in code

  1. #1
    Registered User
    Join Date
    03-28-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    8

    VBA to import birthdays into Outlook - getting error in code

    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!
    Last edited by rtwells; 01-30-2024 at 01:04 PM.

  2. #2
    Registered User
    Join Date
    03-28-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    8

    Re: VBA to import birthdays into Outlook - getting error in code

    Found the error - I'd forgotten to enable the Outlook Object Library.

    Attachment 857718

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need to fix VBA code to import Outlook emails in Excel for Mac
    By knkedia in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2021, 05:33 PM
  2. Error trying to import userform into Outlook: Unable to load UserForm.FRX
    By jeffclanders in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2016, 12:36 PM
  3. MAPI error message when import or export messages in Outlook Express
    By frescoabeyta in forum Microsoft Windows Help
    Replies: 1
    Last Post: 04-08-2016, 09:02 AM
  4. VBA code to import Outlook calendar data directly into Excel
    By Nola111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2016, 04:16 PM
  5. Import Excel to Access code error
    By ewong in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2012, 02:13 PM
  6. Can't find the code to import from Outlook to Excel
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2012, 08:31 AM
  7. Replies: 1
    Last Post: 04-13-2006, 10:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1