0

在 VB6 项目中,此代码用于使用 Microsoft Office Outlook 15.0 对象库通过 Outlook 2013 发送电子邮件:

Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")
Dim mail As Outlook.MailItem
Set mail = objOutlook.CreateItem(olMailItem)
mail.To = txt_Recipient
mail.Subject = txt_Subject
mail.body = txt_Inhalt.Text
mail.Send

现在,当我尝试将相同的代码传输到类模块中时,它不断抛出错误 429,它无法在第三行创建对象。知道为什么它在类模块中不起作用,而在直接在 Command_Click 事件中编码时起作用吗?

类中的代码:

Public objOutlook As outlook.Application
Public Sub MailSenden(ByVal empfaenger As String, ByVal betreff As String, ByVal inhalt As String)
Set objOutlook = CreateObject("Outlook.Application")

Dim mail As outlook.MailItem
Set mail = objOutlook.CreateItem(olMailItem)

mail.To = empfaenger
mail.Subject = betreff
mail.body = inhalt
mail.Send

End Sub

感谢你给与我的帮助!科林

4

1 回答 1

0

我很好奇,当您手边有 Outlook 15.0 类型库(并在您的项目中引用)时,为什么要使用后期绑定。你有没有尝试过:

Set objOutlook = New Outlook.Application
于 2014-02-17T02:38:34.007 回答