Why does this email routine work for me and not my client?

USAMax

Well-known Member
Joined
May 31, 2006
Messages
843
Office Version
  1. 365
Platform
  1. Windows
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?

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.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I'd start by commenting out the On Error Resume Next and then run it for the client.
 
Upvote 0
Rory, so simple... brilliant!

I'll let you know after I try it.
 
Upvote 0
Rory, thank you again. There were a couple of variables that I did not pass and by commenting out the On Error they were easy to resolve.

I was too close to the forest to see the trees I guess. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top