编译错误“未定义用户定义的类型”

时间:2019-05-07 12:03:49

标签: excel vba

我下面有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

reply-to-outlook-mail-from-excel 我希望此宏运行没有任何错误。

1 个答案:

答案 0 :(得分:0)

请按照以下步骤操作:

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

enter image description here