Skip to content

Commit 06d82ac

Browse files
option to send email to participants
1 parent b83d9f4 commit 06d82ac

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Binary file not shown.

Programs.bas

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,63 @@ End Sub
331331

332332

333333

334+
'========================================
335+
'SEND EMAILS TO THE USERS
336+
'========================================
337+
338+
Sub Send_Email()
339+
340+
' define variables
341+
Dim OutApp As Object
342+
Dim OutMail As Object
343+
Dim wshS As Worksheet: Set wshS = Worksheets("Summary")
344+
Set OutApp = CreateObject("Outlook.Application")
345+
Set OutMail = OutApp.CreateItem(0)
346+
Dim question As VbMsgBoxResult
347+
Dim EmailTo As Range: Dim EmailCc As Range
348+
Dim cline As Range: Dim tline As Range
349+
Dim sTo As String: Dim cTo As String
350+
351+
' setup question for the message box
352+
question = MsgBox("Sending email to all contacts, Are you sure? [Preview will follow]", vbYesNo + vbQuestion)
353+
' retrieve emails from the worksheet
354+
Set EmailTo = wshS.Range("B10:B11")
355+
Set EmailCc = wshS.Range("B12:B14")
356+
' joining string for email 'To'
357+
For Each cline In EmailTo
358+
sTo = sTo & ";" & cline.Value
359+
Next
360+
' joining string for email 'Cc'
361+
For Each tline In EmailCc
362+
cTo = cTo & ";" & tline.Value
363+
Next
364+
' cleaning of the strings
365+
sTo = Mid(sTo, 2)
366+
cTo = Mid(cTo, 2)
367+
368+
If question = vbYes Then
369+
370+
With OutMail
371+
.To = sTo
372+
.CC = cTo
373+
.BCC = ""
374+
.Subject = "CarStatusReport" & wshS.Range("B2").Text & "-" & wshS.Range("B3").Text
375+
.Body = "Dear participants, thank you for productive work." & _
376+
vbNewLine & "Please find the file attached: " & ThisWorkbook.Name & _
377+
vbNewLine & "Best regards"
378+
.Attachments.Add ThisWorkbook.Path & "\" & ThisWorkbook.Name 'add this file as attachment
379+
.Display 'with preview mode
380+
'.Send 'sending email directly
381+
End With
382+
383+
Set OutMail = Nothing
384+
Set OutApp = Nothing
385+
386+
ElseIf question = vbNo Then
387+
388+
Exit Sub
389+
390+
End If
391+
392+
End Sub
393+

0 commit comments

Comments
 (0)