0

我正在尝试使用 VBA 代码发送电子邮件,该功能正在运行并且电子邮件已发送,但问题是当函数结束时出现“运行时错误 438 对象不支持此属性或方法”

这是代码:

Public Function SendEmail(ItemName As String, Total_Qnty As Integer)

 Set iMsg = CreateObject("CDO.Message")

 Set iConf = CreateObject("CDO.Configuration")

 Set Flds = iConf.Fields

 ' send one copy with Google SMTP server (with autentication)

 schema = "http://schemas.microsoft.com/cdo/configuration/"

 Flds.Item(schema & "sendusing") = 2

 Flds.Item(schema & "smtpserver") = "smtp.gmail.com"

 Flds.Item(schema & "smtpserverport") = 465

 Flds.Item(schema & "smtpauthenticate") = 1

 Flds.Item(schema & "sendusername") = "example@gmail.com"

 Flds.Item(schema & "sendpassword") = "*****"

 Flds.Item(schema & "smtpusessl") = 1

 Flds.Update


 With iMsg

     .To = "example@hotmail.com"

     .From = "example@gmail.com"

     .Subject = "Mail from gmail"

     .HTMLBody = "The Stock Safty Level of Item: " & ItemName & " is DOWN, The total      quantity you have is: " & Total_Qnty & "!!"

     Set .Configuration = iConf

     .Send

 End With


 Set iMsg = Nothing

 Set iConf = Nothing

 Set Flds = Nothing


End Function

很高兴任何想法..谢谢

4

2 回答 2

0

很可能这是组件之间的二进制兼容性问题。

Microsoft 说“运行时错误 438 - 对象不支持此属性或方法:错误 438 的最常见原因是未维护组件的连续版本之间的二进制兼容性。每个 COM 接口都有一个关联的 GUID,称为接口 ID (IID)。每个 coclass 都有一个关联的 GUID,称为类 ID (CLSID)。在 Visual Basic 中编译 ActiveX 组件时,CLSID 和 IID 被编译到组件的类型库中。 "

在此链接中,它解释了如何解决类似问题:

http://www.vbforums.com/showthread.php?460591-RESOLVED-Runtime-error-438-Object-doesn-t-support-this-property-or-method

于 2013-07-30T11:03:53.183 回答
0

颠倒这些顺序:

Set iMsg = Nothing

Set iConf = Nothing

Set Flds = Nothing

Flds是 iConf 的成员,目前您已经处理掉了该成员。

于 2013-07-30T15:00:55.287 回答