我正在尝试使用vba使用Outlook oft模板发送邮件,但它位于草稿邮件中,而不是从Outlook发送邮件

时间:2020-02-17 09:40:23

标签: excel vba email outlook oft

我使用了下面的编码,该编码先前已用于其他类型的邮件,但是这次不发送邮件。也不要选择excel中提供的电子邮件ID和数据。

Sub Send_Recertification_From_Excel()

Dim oXlWkBk As Excel.Workbook ' Excel Work Book Object
Dim oOLApp As Outlook.Application
Dim oOLMail As MailItem
Dim lRow As Long
Dim olMailItem
Dim sMailID As String
Dim sSalutation As String
Dim sName As String
Dim sDetails As String
Dim sSubject As String
Dim mailsSentString As String
Dim templateName As String
templateName = "C:\Users\m540797\Desktop\Recertification\Recertifications"
On Error GoTo Err_Trap

Set oXlWkBk = ActiveWorkbook
Set oOLApp = GetObject(, "Outlook.Application")
If oOLApp Is Nothing Then
MsgBox "Please Open Outlook.."
Exit Sub
End If

Dim i As Integer

For i = 6 To 50
If Len(Trim(Sheet1.Cells(i, 1))) > 1 Then

    Set oOLMail = oOLApp.CreateItemFromTemplate(templateName)
    sMailID = Sheet1.Cells(i, 4)
    sSubject = "Recertification"


    With oOLMail
        .BodyFormat = olFormatHTML
        .HTMLBody = Replace(.HTMLBody, "<NAME>", Sheet1.Cells(i, 3))
        .SentOnBehalfOfName = "my mail ID given here"
        .To = sMailID
        .Subject = sSubject
        .CC = Sheet1.Cells(i, 6)
        .Send


    End With

    oOLMail.Send

Else
    Exit For
End If
Next i
MsgBox "Mails successfully sent to :" + vbCrLf + mailsSentString + vbCrLf + "with using the template :" + templateName

Destroy_Objects:
If Not oOLApp Is Nothing Then Set oOLApp = Nothing


Err_Trap:
If Err <> 0 Then
MsgBox Err.Description, vbInformation, "VBADUD AutoMail"
Err.Clear
GoTo Destroy_Objects
End If

End Sub

没有给出任何错误仅表示邮件已成功发送,但邮件处于草稿中。 “可以请您检查并确认这是什么错误,否则我会丢失某些东西”

0 个答案:

没有答案