在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
感谢您的帮助,您可以给我! 科林
答案 0 :(得分:0)
我很好奇为什么在使用Outlook 15.0类型库(并在项目中引用)时使用后期绑定。你试过了吗?
Set objOutlook = New Outlook.Application