Getting a custom type not specified when running code

Does anyone know why I get a "custom type not defined" error in Function GetOutlookApp() As Outlook.Application at the bottom of this code?

 Sub CreateAppointments() Dim cell As Excel.Range Dim rng As Excel.Range Dim wholeColumn As Excel.Range Dim startingCell As Excel.Range Dim oApp As Outlook.Application Dim tsk As Outlook.TaskItem Dim wkbk As Excel.Workbook Dim wksht As Excel.Worksheet Dim lastRow As Long Dim arrData As Variant Dim i As Long 

'launch Outlook app

 Set oApp = GetOutlookApp If oApp Is Nothing Then MsgBox "Could not start Outlook.", vbInformation Exit Sub End If 

'get a range of worksheets into an array at a time

 Set wkbk = ActiveWorkbook Set wksht = wkbk.ActiveSheet Set wholeColumn = wksht.Range("B:B") lastRow = wholeColumn.End(xlDown).Row - 2 Set startingCell = wksht.Range("B2") Set rng = wksht.Range(startingCell, startingCell.Offset(lastRow, 1)) arrData = Application.Transpose(rng.Value) 

'loop and create tasks for each record

 For i = LBound(arrData, 2) To UBound(arrData, 2) Set tsk = oApp.CreateItem(olTaskItem) With tsk .DueDate = arrData(2, i) .Subject = arrData(1, i) .Save End With Next I End Sub Function GetOutlookApp() As Outlook.Application On Error Resume Next Set GetOutlookApp = CreateObject("Outlook.Application") End Function 
+5
source share
2 answers

How to automate Outlook from another program. This article describes all the necessary steps for automating Outlook. It states:

To use early binding, you first need to access an accessible library of Outlook objects. To do this from Visual Basic (VB) or Visual Basic for Applications, follow these steps:

  • In the Visual Basic Editor, on the Tools menu, click Links.
  • Select the check box for the Microsoft Outlook 15.0 object library, and then click OK.
+7
source

I had the same problem when I use Outlook in my Excel VBA scripts and I select:

Tools> Links> Check the box next to "Microsoft Outlook 15.0 Object Library.

0
source

All Articles