首页 > 解决方案 > 编译错误“未定义用户定义类型”

问题描述

我有以下 ReplyAll 邮件代码,在运行此代码期间,我遇到以下错误:

编译错误 - 未定义用户定义类型

我已在下面粘贴代码并尝试运行此代码,但如上所述出现编译错误。

Sub Test()

Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1

For Each olMail In Fldr.Items
If InStr(olMail.Subject, "Application for Privilege Leave - Leave ID - Dev-PL-45252-4") <> 0 Then
olMail.Display

i = i + 1
End If
Next olMail
End Sub

从excel回复到outlook-mail- 我希望这个宏运行没有任何错误。

标签: excelvba

解决方案


请按照以下步骤操作:

  1. 转到您拥有代码的 Microsoft Visual Basic 编辑器
  2. 单击工具菜单-> 参考
  3. 在打开的窗口中,找到 Microsoft Outlook 14.0 对象库(版本可能因系统而异,具体取决于您拥有的 Office 版本)
  4. 选择它并单击确定
  5. 现在运行您的代码。

在此处输入图像描述


推荐阅读