+ 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
    Registered User
    Join Date
    12-17-2019
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365 E3
    Posts
    3

    Post VBA to Send Email with Outlook

    Hi,

    I have never used VBA before but it seems to be the only way to automate emails with the information I have in my excel sheet.
    I use outlook as my email application.

    Here is what I have:

    Sheet 1 named "Data"
    - Row 1 is the headers of each column
    - Column A is "Die Number", where I have part numbers and i have hundreds of rows of part numbers.
    - I have conditional formatting that will only fill blank cells in orange (as reminder of upcoming due date) and red (due/past due).
    - This conditional formatting spans cells H2:N999.

    Sheet 3 name "Email List"
    A list of email addresses I would like to sent reminder/warning too


    What I require/need help on:

    I want to send 1 email everyday with the click of a button that details what die number has an orange warning or red warning in each row.
    (Example for orange - Die 12345 - Please check die for completion ETA.)
    (Example for red - Die 12345 is due Today/Past Due, please follow asap.)


    Thank you very much for the help in advance.

  2. #2
    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

    To help prepare macros, please attached an Excel sample file.
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    12-17-2019
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365 E3
    Posts
    3

    Re: VBA to Send Email with Outlook

    I was having difficulty uploading directly, so here is the sample file I uploaded to google drive

    **Replace all "*" with "/"

    https:**drive.google.com*file*d*1n1k7hLIGpwubYtXX06-Hjk9cSqGoCQq6*view?usp=sharing

  4. #4
    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

    Is the list of Red or Orange Dies long ???
    In other word, do we attach a file ( PDF one) with the list of dies or do we record the Dies reference in the Email ???

  5. #5
    Registered User
    Join Date
    12-17-2019
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365 E3
    Posts
    3

    Re: VBA to Send Email with Outlook

    Quote Originally Posted by PCI View Post
    Is the list of Red or Orange Dies long ???
    In other word, do we attach a file ( PDF one) with the list of dies or do we record the Dies reference in the Email ???
    Just the email body includes reference to the part number in column A. and Each line is the part number and what kind of warning it is. (refer to my example for email body sample)


    So in the end the email will look something like:

    Subject: Dies that require checking
    Body: Die "XXXXX" - Please check die for completion ETA.
    Die "YYYYY" - Please check die for completion ETA.
    Die "ZZZZZ" - Due Today/Past Due, please follow asap.
    Last edited by BlackShiraya; 12-19-2019 at 12:01 PM.

  6. #6
    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

+ 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