Obteniendo un tipo de error definido por el usuario no definido al ejecutar el código
¿Alguien sabe por qué recibo un error "tipo definido por el usuario no definido" en elFunction GetOutlookApp() As Outlook.Application
al final de con este código?
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
'iniciar aplicación de Outlook
Set oApp = GetOutlookApp
If oApp Is Nothing Then
MsgBox "Could not start Outlook.", vbInformation
Exit Sub
End If
'obtenga el rango de la hoja de trabajo en una matriz de una sola vez
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)
'recorrer la matriz y crear tareas para cada registro
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