Send Last Row Information in Automatic Outlook Email

SteelheadBen

New Member
Joined
Jun 26, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Greetings,

I have this set up perfectly, except it opens all the rows in many separate emails. I want this module to only make 1 email containing the latest cell information in the last row in the spreadsheet and send one email containing the last row information. Can anyone help? I used a template to create this, so there may be unnecessary information in this code.

Thank you for your time in helping me with this!

VBA Code:
Sub sendCustEmails()

    Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    Dim objEmail As Object
    
    Application.EnableEvents = True
    
    intRow = 2
    strClientID = ThisWorkbook.Sheets("Sheet2").Range("A" & intRow).Text
    
    While (strClientID <> "")
    
        Set objEmail = objOutlook.CreateItem(olMailItem)
    
        strMailSubject = ThisWorkbook.Sheets("Sheet2").Range("A2").Text
        strMailBody = ThisWorkbook.Sheets("Sheet2").Range("A2").Text
        strMonth = ThisWorkbook.Sheets("Sheet2").Range("C2").Text
        
        strSO = ThisWorkbook.Sheets("Sheet2").Range("A" & intRow).Text
        strCustomerName = ThisWorkbook.Sheets("Sheet2").Range("B" & intRow).Text
        strDueDate = ThisWorkbook.Sheets("Sheet2").Range("C" & intRow).Text
        strDueStatus = ThisWorkbook.Sheets("Sheet2").Range("D" & intRow).Text
        strCreationDate = ThisWorkbook.Sheets("Sheet2").Range("E" & intRow).Text
        strCompletionDate = ThisWorkbook.Sheets("Sheet2").Range("F" & intRow).Text
        strOrderStatus = ThisWorkbook.Sheets("Sheet2").Range("G" & intRow).Text
        strBoxSize = ThisWorkbook.Sheets("Sheet2").Range("H" & intRow).Text
        strWeight = ThisWorkbook.Sheets("Sheet2").Range("I" & intRow).Text
        
        With objEmail
            .To = "WILL FILL OUT LATER"
            .CC = "WILL FILL OUT LATER"
            .Subject = "order # " & strMailSubject & " is Complete"
           
 .Body = "Team," & vbNewLine & vbNewLine & "This email is to notify that order   " & strSO & "   for   " & strCustomerName 
& "   is complete and ready for shipment. Box and weight information is provided below." 
& vbNewLine & vbNewLine & "Box Size:  " & strBoxSize & vbNewLine & "Weight:  " 
& strWeight & vbNewLine & vbNewLine 
& "For any additional information about this order, please contact me" 
& vbNewLine & vbNewLine & "Thanks," & vbNewLine & vbNewLine & "Shipping Department"
            
.Display
        End With
        
        intRow = intRow + 1
        strClientID = ThisWorkbook.Sheets("Sheet2").Range("A" & intRow).Text
    Wend
    
    MsgBox "Done"

End Sub

1656280246616.png
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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