The person I wrote this for and I both work at the same company with the same software, Office 365. The entire macro runs and compiles the data but for the person I wrote does not see the emails. Why won't it display the email for her?
An interesting point is that when this code was included within the main routine and it was sending out more than one email I could not clear the .attachments so I put it in its own routine and it worked! The client never tried it before I separated this routine.
Code:
Public Sub SendEmailWithAttachments(strContact As String, SendTo As String, strSubject As String, varBodyText, strBookPath As String, strPDFPath As String)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
' Change the mail address and subject in the macro before you run this procedure.
With OutMail
If wsEmail.Cells(lngEmlRow, intEmail) <> "" Then
.To = "MyClient@AnyDomain.com"
Else
.To = wsEmail.Cells(lngEmlRow, intEmail)
End If
.CC = ""
.BCC = ""
.Subject = strSubject
If InStr(1, wsEmail.Cells(lngEmlRow, intCustName), " ") > 0 Then
.Body = "Hello " & Trim(Left(strContact, _
InStr(1, strContact, " "))) & "," & vbLf & varBodyText.Value
Else
.Body = "Hello " & Trim(wsEmail.Cells(lngEmlRow, intCustName)) & "," & vbLf & varBodyText.Value
End If
.attachments.DeleteAll
.attachments.Add (strBookPath) 'wbTemp.strCurFile
' You can add other files by uncommenting the following line.
.attachments.Add (strPDFPath)
' In place of the following statement, you can use ".Display" to
' display the mail.
.Display
End With
On Error GoTo 0
End Sub
An interesting point is that when this code was included within the main routine and it was sending out more than one email I could not clear the .attachments so I put it in its own routine and it worked! The client never tried it before I separated this routine.