Send Email to the New Customers Only While Other Customer's Data is There and has been Marked as Mail Sent

Ancient Origin

New Member
Joined
Aug 11, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hello Team,
.
I am a new bie who can do research but doesn't know coding. I am good in making Logics and know initially what my end result should be like. I am making a VBA Code in which new Customer's Information will get copeid below the Old Customer's Information. that is also gets done automatically. I have made the VBA Code of Sending Email to the Customer by copying and joinging someone's else work and tested it as well thats its working. Once Email is Marked to the Customer, i get the "Mail Sent" Value in "I" Column. This is what Segregates the Old Customer from the New Customer. Now Since we have already marked an email to the Old Customer, i want to send email only to the new customer automatically without any manual intervention. So please help me if I need to make a Loop or If Logic can work here. Also in H Column I want to connect it with Logic, If by any chance it gives me result of "Duplicate". Logic Will End by not sending the email to the customer. Coding I have joined so far and is working on my PC is mentioned below :

VBA Code:
Option Explicit

Sub Send_Email()
ActiveWorkbook.Save
      
Dim OutApp As Object
Dim OutMail As Object
Dim SigString As String
Dim Signature As String
Dim Path As String
Dim inam As String
Dim i As Integer
Dim lastrow As Integer

Set OutApp = CreateObject("Outlook.Application")

lastrow = Application.WorksheetFunction.CountA(Sheet6.Range("E:E"))

For i = 2 To lastrow
Path = Sheet6.Range("F" & i)
inam = Sheet6.Range("G" & i)

Set OutMail = OutApp.CreateItem(0)

SigString = "SIGNATURE PATH OF OUTLOOK"
 
If Dir(SigString) <> "" Then
       Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If
On Error Resume Next

With OutMail

    .To = Sheet6.Range("E" & i).Value
    .BCC = "FIXED BACK UP EMAIL ID"
    .Subject = "AUTOMATED : INVOICE No. " & Sheet6.Range("B" & i).Value
    .HTMLBody = "<BODY style = font-size:11pt; font-familt:Cambria>" & _
    "INFORMATION TO THE CUSTOMER - PLEASE IGNORE THIS"
    
    .Attachments.Add Path & inam & ".pdf"
    .Send
     End With

Sheet6.Range("I" & i).Value = "Mail Sent"
Next i

MsgBox "Mail Sent"
 
On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    
    
End Sub


Function GetBoiler(ByVal sFile As String) As String
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.ReadAll
    ts.Close
End Function
 

Attachments

  • 2022-08-11_145649.jpg
    2022-08-11_145649.jpg
    97.7 KB · Views: 19

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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