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

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

问题描述

有人知道为什么为什么在此代码底部的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天全站免登陆