+ Reply to Thread
Results 1 to 6 of 6

VBA to Send Email with Outlook

Hybrid View

BlackShiraya VBA to Send Email with Outlook 12-17-2019, 12:08 PM
PCI Re: VBA to Send Email with... 12-17-2019, 02:34 PM
BlackShiraya Re: VBA to Send Email with... 12-18-2019, 09:10 AM
PCI Re: VBA to Send Email with... 12-19-2019, 06:34 AM
BlackShiraya Re: VBA to Send Email with... 12-19-2019, 11:58 AM
PCI Re: VBA to Send Email with... 12-19-2019, 03:18 PM
  1. #1
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,086

    Re: VBA to Send Email with Outlook

    Here what could be done
    Option Explicit
    
    Sub Treat()
    Const DataWsN = "Data"
    Const OrgMsg = " Please check die for completion ETA"
    Const RedMsg = " is due Today/Past Due, please follow asap"
    Const MsgSt = "Die "
    
    Dim WkRg  As Range, WkRg1 As Range, Rg As Range
    Dim LR As Integer
    
    Dim EmailSubject  As String
    Dim EmailStart1 As String
    Dim EmailBody  As Range
    Dim EmailEnd1 As String, EmailEnd2 As String
    Dim Email_List As Range
    Dim DestEmail As String
    Dim EmailList As Range
    
    Dim myOlApp As Outlook.Application
    Dim myItem As Outlook.MailItem
        Set myOlApp = CreateObject("Outlook.Application")
        Set myItem = myOlApp.CreateItem(olMailItem)
        
    Dim DataWs As Worksheet
        Set DataWs = Sheets(DataWsN)
        
    '---  People Email list preparation
        Set EmailList = Range("EmailList")
        If EmailList.Rows.Count = 0 Then MsgBox (" No email to send information "): Exit Sub
        DestEmail = ""
        For Each Rg In EmailList
            If (Len(Rg) <> 0) Then DestEmail = DestEmail & "," & Rg
        Next Rg
        DestEmail = Mid(DestEmail, 2)
    
    '---  Email info
        EmailSubject = Range("EmailSubject")
        EmailStart1 = Range("EmailStart1")
        EmailEnd1 = Range("EmailEnd1")
        EmailEnd2 = Range("EmailEnd2")
        
        With DataWs
            Set EmailBody = Range("EmailBody")
            EmailBody.ClearContents
    '       Review  Dies list
            Set WkRg = .UsedRange
            If (.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False '  REMOVE  AUTOFILTER  IF  EXIST
            
    '       RED  Dies
            WkRg.AutoFilter Field:=8, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor
            LR = .Cells(Rows.Count, 1).End(3).Row
            If (LR > 1) Then
                Set WkRg1 = Range(.Cells(2, 1), .Cells(LR, 1))
                For Each Rg In WkRg1.SpecialCells(xlCellTypeVisible)
                    EmailBody = EmailBody & vbCrLf & _
                        MsgSt & Rg & RedMsg
                Next Rg
                EmailBody = Mid(EmailBody, 2)
            End If
            
    '       ORANGE  Dies
            WkRg.AutoFilter Field:=8, Criteria1:=RGB(255, 192, 0), Operator:=xlFilterCellColor
            LR = .Cells(Rows.Count, 1).End(3).Row
            If (LR > 1) Then
                Set WkRg1 = Range(.Cells(2, 1), .Cells(LR, 1))
                For Each Rg In WkRg1.SpecialCells(xlCellTypeVisible)
                    EmailBody = EmailBody & vbCrLf & _
                        MsgSt & Rg & OrgMsg
                Next Rg
            End If
        End With
    
        EmailBody = EmailStart1 & _
                    EmailBody & vbCrLf & _
                    EmailEnd1 & vbCrLf & _
                    EmailEnd2 & vbCrLf
                    
    '---  Send Email
        Application.DisplayAlerts = False
        With myItem
            .To = DestEmail
            .Subject = EmailSubject
            .Body = EmailBody
            .Send
        End With
        Application.DisplayAlerts = True
        
    '---  Close
        Set myItem = Nothing
        Set myOlApp = Nothing
        MsgBox ("  Email sent")
       
    End Sub
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Send Email in Outlook
    By Illogical90 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2018, 11:53 AM
  2. [SOLVED] VBA to send email with outlook
    By Keibri in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-10-2018, 02:34 PM
  3. Send email from shared Outlook email address
    By rousseauassociates in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2016, 07:33 AM
  4. Send an email via outlook from and address other than your default email.
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2015, 06:15 PM
  5. Email Macro o send Outlook Email
    By asivaprakash in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2013, 07:05 PM
  6. send selected range in email with default outlook email signature included
    By mdsickler in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2013, 10:50 PM
  7. Send Email from outlook
    By wawansur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2010, 04:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1