运行程序以通过Outlook发送电子邮件时,出现标题中提到的错误。谁能帮忙吗?突出显示第二行-
enter image description here将 olApp设置为Outlook.Application
代码:
Sub send_mail(address As String, subject As String, mail_body As String)
'
'
Dim **olApp As Outlook.Application**
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.mailitem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = address
olMail.subject = "Maintenance Activity at: " & subject
olMail.Body = "Equipment to be maintained: " & mail_body
olMail.CC = Sheets("Expiry").Range("M8").Value
olMail.send
End Sub
Sub mass_mail()
n = Now()
MsgBox "date: " & n
If MsgBox("Are You Sure? ", vbYesNo, " Warning! ") = vbYes Then
Dim row_number As Integer
row_number = 4
Do
DoEvents
row_number = row_number + 1
If Range("D" & row_number).Value >= n And Range("D" & row_number).Value < (n + 30) Then
Call send_mail(Sheet1.Range("L" & row_number), Sheet1.Range("C" & row_number), Sheet1.Range("D" & row_number))
MsgBox "Date: " & Range("D" & row_number).Value
End If
Loop Until row_number = 10
MsgBox ("Messages(s) Sent!")
End If
End Sub
答案 0 :(得分:1)
早期绑定的库参考:
您需要在项目引用中添加对Outlook库的引用。
在可视化基本编辑器中,您需要转到“工具”>“引用”,然后向下滚动以找到适合您Office版本的Microsoft Outlook对象库
对我来说,这是16.0版
后期绑定:
或者,您可以使用以下方法将库调用转换为后期绑定,它不需要添加库引用,并且在将应用程序分发给可能具有不同Office版本的其他用户时更加安全。
_dbContext.SalesOrderLookup()
.Where(x => (x.Status.EqualsTrim("Open") == parameters.Open)
|| (x.Status.EqualsTrim("Closed") == parameters.Closed)
|| (x.Status.EqualsTrim("Cancel") == parameters.Canceled)).ToList();
早期绑定和后期绑定的信息: