Does anyone know why I'm getting a "user-defined type not defined" error in the Function GetOutlookApp() As Outlook.Application
at the bottom of with 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
' start Outlook app
Set oApp = GetOutlookApp
If oApp Is Nothing Then
MsgBox "Could not start Outlook.", vbInformation
Exit Sub
End If
' get worksheet range into an array in one go
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 through array 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
This error has the following cause and solution: You used an Option Explicit statement to require the explicit declaration of variables, but you used a variable without declaring it. Explicitly declare the variable, or change the spelling of the variable to match that of the intended variable.
Step 1: Write the subprocedure for VBA Type Mismatch. Step 2: Again assign a new variable, let's say “A” as Byte data type. Let's understand the Byte Data type here. Byte can only store the numerical value from 0 to 255.
You create a user defined type using the Type statement. This combines multiple data types into a single data type. You define custom data types outside of procedures at the top of your module. Once you have created your type use the Dim statement to declare a variable of that type.
The How to automate Outlook from another program article describes all the required steps for automating Outlook. It states:
To use early binding, you first need to reference the available Outlook object library. To do this from Visual Basic (VB) or Visual Basic for Applications, follow these steps:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With