Compile Error User defined type not defined

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
630
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
"Microsoft Office 16.0 Object Library" is checked

VBA Code:
Sub ExtractCalendarEvents()
    Dim olApp As Outlook.Application [B]'ERROR HAPPENS HERE[/B]
    Dim olNamespace As Outlook.Namespace
    Dim olFolder As Outlook.Folder
    Dim olItems As Outlook.Items
    Dim olAppointment As Outlook.AppointmentItem
    Dim i As Integer

    ' Create a new Excel workbook
    Dim xlApp As Excel.Application
    Dim xlWorkbook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    
    Set xlApp = New Excel.Application
    Set xlWorkbook = xlApp.Workbooks.Add
    Set xlSheet = xlWorkbook.Sheets(1)
    
    ' Set up Outlook objects
    Set olApp = New Outlook.Application
    Set olNamespace = olApp.GetNamespace("MAPI")
    Set olFolder = olNamespace.GetDefaultFolder(olFolderCalendar)
    Set olItems = olFolder.Items
    
    ' Add headers to the Excel sheet
    xlSheet.Cells(1, 1).Value = "Subject"
    xlSheet.Cells(1, 2).Value = "Start"
    xlSheet.Cells(1, 3).Value = "End"
    
    ' Loop through the calendar items and add them to the Excel sheet
    i = 2
    For Each olAppointment In olItems
        If TypeName(olAppointment) = "AppointmentItem" Then
            xlSheet.Cells(i, 1).Value = olAppointment.Subject
            xlSheet.Cells(i, 2).Value = olAppointment.Start
            xlSheet.Cells(i, 3).Value = olAppointment.End
            i = i + 1
        End If
    Next olAppointment
    
    ' Save and open the workbook
    xlWorkbook.SaveAs "C:\Path\To\Save\CalendarEvents.xlsx"
    xlApp.Visible = True
    
    ' Clean up
    Set olApp = Nothing
    Set olNamespace = Nothing
    Set olFolder = Nothing
    Set olItems = Nothing
    Set xlApp = Nothing
    Set xlWorkbook = Nothing
    Set xlSheet = Nothing
    
    MsgBox "Events have been extracted and saved to an Excel file.", vbInformation
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
MS Office 16 object is checked as stated. Thank you

Yes I read that but I was referring to Outlook object library

1737823638445.png
 
Upvote 0
That is NOT what dmt32 is saying. Look at what he put in bold in post#2
 
Upvote 0
I have two versions of Outlook on my laptop. I have Office 365 and Office 2010. Would this make a difference?
 
Upvote 0
I have two versions of Outlook on my laptop. I have Office 365 and Office 2010. Would this make a difference?

not able to offer a view on that - I am running office 2021 on this laptop & your code, with that library checked, compiled ok.

Dave
 
Upvote 0

Forum statistics

Threads
1,225,969
Messages
6,188,111
Members
453,460
Latest member
Cjohnson3

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