Kmahraz
Member
Hello,
Looking for someone to help with the code below, trying to BCC a list of email in column (J).
Regards,
K
Looking for someone to help with the code below, trying to BCC a list of email in column (J).
Regards,
K
Code:
Sub EmailReport()
Dim OutApp As Object
Dim OutMail As Object
'Use presence of a Path to determine if a mail is sent.
Set Rng = Range(Range("I2"), Range("I" & Rows.Count).End(xlUp))
For Each cell In Rng
Path = cell.Value
If Path <> "" Then
'Get Date info from Path
Dte = Right(Path, Len(Path) - InStrRev(Path, "\"))
'Get WHOTO to check for filename (Column A)
FilNmeStr = cell.Offset(0, -8).Value
'Email Address
ToName = cell.Offset(0, -5).Value
'Create Recipient List
RecpList = ""
For x = 1 To 4
Recp = cell.Offset(0, -x).Value
If Recp <> "" Then
Recp = cell.Offset(0, -x).Value
End If
RecpList = RecpList & ";" & Recp
Next
ccTo = RecpList
'Get Name
FirstNme = cell.Offset(0, -7).Value
Surname = cell.Offset(0, -6).Value
'Loop through files in Path to see if
ClientFile = Dir(Path & "\*.*")
Do While ClientFile <> ""
If InStr(ClientFile, FilNmeStr) > 0 Then
AttachFile = Path & "\" & ClientFile
MailBody = "Dear " & FirstNme & vbNewLine & vbNewLine _
& "Please find attached a copy of your DOP report for " & Dte _
& vbNewLine & vbNewLine _
& "WHOTO: " & cell.Offset(0, -8).Value _
& vbNewLine & _
"Distributor Principal: " & FirstNme & " " & Surname _
& vbNewLine & _
"With thanks" & _
Signature
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(o)
With OutMail
.Subject = "DOP Report for - " & Dte
.To = ToName
.cc = ccTo
.Body = MailBody
.Attachments.Add (AttachFile)
.Display
'.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
RecpList = ""
End If
ClientFile = Dir
Loop
End If
Next
End Sub