运行代码时获取用户定义类型未定义错误 [英] Getting user-defined type not defined error when running code

查看:30
本文介绍了运行代码时获取用户定义类型未定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么我在使用此代码底部的 Function GetOutlookApp() As Outlook.Application 中收到未定义用户定义的类型"错误?

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

' 启动 Outlook 应用

' 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

推荐答案

如何自动化来自另一个程序的 Outlook 文章描述了自动化 Outlook 所需的所有步骤.它指出:

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

要使用早期绑定,您首先需要引用可用的 Outlook 对象库.要从 Visual Basic (VB) 或 Visual Basic for Applications 执行此操作,请执行以下步骤:

  1. 在 Visual Basic 编辑器中,在工具"菜单上,单击引用".
  2. 单击以选中 Microsoft Outlook 15.0 对象库复选框,然后单击确定.

这篇关于运行代码时获取用户定义类型未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆