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
source share