简体   繁体   English

后期绑定编译错误:未定义引用Excel VBA中的Outlook mailitem的用户定义类型

[英]Late binding compile error: User-defined type not defined referencing Outlook mailitem in Excel VBA

I am using late binding from Excel. 我正在使用Excel的后期绑定。

I get 我懂了

Compiler Error: User defined type not defined 编译器错误:未定义用户定义的类型

for: 对于:

If TypeOf olMail Is MailItem Then

I declare the following variables: 我声明以下变量:

Dim olApp As Object
Dim olNs As Object
Dim Fldr As Object
Dim olItms As Object
Dim olMail As Object

Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = Fldr.Items

The code was working but I had to change to late binding because a user is not using the same Outlook version. 该代码正常工作,但由于用户使用的Outlook版本不同,我不得不更改为后期绑定。

I'm guessing the reason you get the error is because you no longer have a reference to the outlook object library, and thus MailItem is an unknown type. 我猜您收到错误的原因是因为您不再有对Outlook对象库的引用,因此MailItem是未知类型。

Instead of using TypeOf 而不是使用TypeOf

If TypeOf olMail Is MailItem Then

use the TypeName function to compare the object type name to a string... 使用TypeName函数将对象类型名称与字符串进行比较...

If TypeName(olMail) = "MailItem" Then

(note I'm assuming the type name will be MailItem , but you can always throw in MsgBox TypeName(olMail) just to be sure!) (请注意,我假设类型名称将为MailItem ,但是为了确保可以随时输入MsgBox TypeName(olMail) !)

Type Name function is somewhat expensive. 类型名称功能有些昂贵。 Class property (implemented by all OOM objects) would be a better aalternative. Class属性(由所有OOM对象实现)将是更好的替代方法。 Check that oMail.Class = 43 (43 is OlObjectClass.olMail constant) 检查oMail.Class = 43 (43是OlObjectClass.olMail常数)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复编译错误:在 Outlook 中使用 Excel VBA 时未定义用户定义的类型? - How to fix Compile Error: User-defined type not defined when using Excel VBA from Outlook? Excel VBA 编译抛出“未定义用户定义的类型”错误 - Excel VBA Compile throws a “User-defined type not defined” error 在 Excel VBA 中将变量声明为 Outlook.MailItem 时出错:未定义用户定义类型 - Error declaring a variable as Outlook.MailItem in Excel VBA: user defined type not defined Outlook 错误:未定义用户定义类型引用 Excel 工作簿 - Outlook Error: user-defined type not defined referring to Excel workbook 使用Excel VBA发送Outlook电子邮件会生成错误:未定义用户定义的类型 - Sending Outlook Email Using Excel VBA generates error: user-defined type not defined 编译错误:未定义用户定义的类型Access / Excel参考 - Compile Error: User-defined type not defined Access/Excel Reference VBA'用户定义类型未定义'与Outlook编译错误 - VBA 'User Defined Type Not Defined' Compile Error with Outlook Excel VBA On用户定义类型的错误处理 - Excel VBA On Error handling with User-Defined Type 如何在Microsoft VBA中解决此错误消息“编译错误:未定义用户定义类型” - How can I resolve this error message “Compile Error: User-defined type not defined” in Microsoft VBA excel vba userforms:未定义的用户定义类型 - excel vba userforms: user-defined type not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM