How to Send Automatic Email from Excel to Outlook (4 Methods)

We have Employee Restructured Salary data in Excel, and we want to send automatic emails using Outlook.

Dataset-Send Automatic Email from Excel to Outlook


Opening Microsoft Visual Basic and Inserting Code in Module

Opening the VBA Window:

  • Using Keyboard Shortcuts: Press Alt + F11.
  • Using the Developer Tab: In an Excel worksheet, go to the Developer Tab and select Visual Basic.

Microsoft Visual Basic-Send Automatic Email from Excel to Outlook

  • Using the Worksheet Tab: Go to any worksheet, right-click on its name and choose View Code from the Context Menu.

View Code


Inserting a Module in Microsoft Visual Basic:

  • Using Sheet Options: Select a Worksheet, then right-click on it, select Insert from the Context Menu, then choose Module.

Module-Send Automatic Email from Excel to Outlook

  • Using the Toolbar: Select Insert from the Toolbar and choose Module.

Module


Method 1 – Using Excel VBA Macro to Automatically Send Email from Outlook to the Selected Recipients

Steps:

  • Go to the Insert tab.
  • Select Shapes.
  • Select any of the offered shapes (i.e., Rectangular: Rounded Corners).

Specific Recipients-Send Automatic Email from Excel to Outlook

  • Drag the Plus Icon wherever you want to insert the Shape as shown in the image below.

Dragging

  • Choose a preferred Shape Fill and Outline Color, then right-click on the shape.
  • Click on Edit Text to insert text.

Edit Text

  • Open Microsoft Visual Basic and insert a Module.
  • Paste the following Macro in the Module.
Sub ExcelToOutlookSR()
Dim mApp As Object
Dim mMail As Object
Dim SendToMail As String
Dim MailSubject As String
Dim mMailBody As String
For Each r In Selection
    SendToMail = Range("C" & r.Row)
    MailSubject = Range("F" & r.Row)
    mMailBody = Range("G" & r.Row)
Set mApp = CreateObject("Outlook.Application")
Set mMail = mApp.CreateItem(0)
With mMail
    .To = SendToMail
    .Subject = MailSubject
    .Body = mMailBody
    .Display ' You can use .Send
    End With
Next r
End Sub

Macro

1 – starts the macro procedure by declaring the variables as Object and String.

2 – runs a VBA FOR loop for each row in the selection to assign Email’s Send To, Subject, and Body using row entries.

3 – assigns variables.

4 – performs the VBA With statement to populate Outlook items such as Send To, Mail Subject, etc. Here the macro only executes the Display command to bring out Outlook with an email draft. However, if Send command is used in place or after Display, Outlook will send the created email to the selected recipients.

5 – finishes the VBA FOR loop.

  • Return to the worksheet.
  • Right-click on the Shape and select Assign Macro from the Context Menu options.

Assign Macro

  • Select the Macro ExcelToOutlookSR under the Macro name and choose the Macro in option as This Workbook.
  • Click on OK.

Assign Macro

  • In the worksheet, select one or multiple employees, then click on the Shape.

Click on Shape Button

  • Excel prompts Outlook to launch and creates or sends emails to the selected employees. Since we selected two employees, Outlook generated two different email drafts ready to be sent.

Email draft-Send Automatic Email from Excel to Outlook

  • Use the Send command to automatically send emails from Excel to Outlook using cell entries.

Read More: How to Send Excel File to Email Automatically


Method 2 – Sending Email Automatically from Excel to Outlook Depending on Specific Cell Value

We have Quarterly Sales Data as depicted below. After achieving a target (i.e., Sales > 2,000), we will automatically prompt Outlook to send an email from Excel to an assigned email.

Dataset-Send Automatic Email from Excel to Outlook

  • Use the following macro code in a VBA Module.
Option Explicit
Dim Rng As Range
Sub Worksheet_Change(ByVal mRng As Range)
On Error Resume Next
If mRng.Cells.Count > 1 Then Exit Sub
Set Rng = Intersect(Range("F17"), mRng)
If Rng Is Nothing Then Exit Sub
If IsNumeric(mRng.Value) And Target.Value > 2000 Then
Call ExcelToOutlook
End If
End Sub
Sub ExcelToOutlook()
Dim mApp As Object
Dim mMail As Object
Dim mMailBody As String
Set mApp = CreateObject("Outlook.Application")
Set mMail = mApp.CreateItem(0)
mMailBody = "Greetings Sir" & vbNewLine & vbNewLine & _
"Our outlet has quarterly Sales more than the target." & vbNewLine & _
"It's a confirmation mail." & vbNewLine & vbNewLine & _
"Regards" & vbNewLine & _
"Outlet Team"
On Error Resume Next
With mMail
        .To = "[email protected]"
        .CC = ""
        .BCC = ""
        .Subject = "Notification on Achieving Sales Target"
        .Body = mMailBody
        .Display 'or you can use .Send
End With
On Error GoTo 0
Set mMail = Nothing
Set mApp = Nothing
End Sub

Macro

1 – assigns a cell (i.e., F17) within a range to execute the VBA IF statement. If the statement results in True, the macro calls another macro for execution.

2 – declares variable types and assign them to populate Outlook’s entries.

3 – performs VBA With statement to assign variables to email entries. Use the Send command instead of Display in case you directly want to send emails without reviewing them. The recipient email is inserted within the macro. Use alternative methods in case you want an automatic insertion of the recipient’s email id.

4 – clears certain variables.

  • Use the F5 key to run the macro.
  • Excel fetches Outlook with a draft email created automatically as shown.
  • You can click on Send or auto-send using the Send command in the macro.

Specific Value-Send Automatic Email from Excel to Outlook

Read More: Automatically Send Emails from Excel Based on Cell Content


Method 3 – Creating VBA Macro to Send Email with the Active Worksheet from Excel by Outlook

  • Insert the following macro in a Module.
Function ExcelOutlook(mTo, mSub As String, Optional mCC As String, Optional mBd As String) As Boolean
On Error Resume Next
Dim mApp As Object
Dim rItem As Object
Set mApp = CreateObject("Outlook.Application")
Set rItem = mApp.CreateItem(0)
With rItem
     .To = mTo
     .CC = ""
     .Subject = mSub
     .Body = mBd
     .Attachments.Add ActiveWorkbook.FullName
     .Display 'or you can use .Send
End With
Set rItem = Nothing
Set mApp = Nothing
End Function
Sub OutlookMail()
Dim mTo As String
Dim mSub As String
Dim mBd As String
mTo = "[email protected]"
mSub = "Quarterly Sales Data"
mBd = "Greetings Sir" & vbNewLine & vbNewLine & _
"Kindly find Outlet's Quarterly Sales data attached with this mail." & vbNewLine & _
"It's a notification mail." & vbNewLine & vbNewLine & _
"Regards" & vbNewLine & _
"Outlet Team"
If ExcelOutlook(mTo, mSub, , mBd) = True Then
    MsgBox "Successfully created the Mail draft or Sent"
End If
End Sub

Macro-Send Automatic Email from Excel to Outlook

1 – declares and set the variables.

2 – assigns the commands using the VBA With statement. Use the Display or Send command for reviewing or direct sending emails respectively.

3 – clears the previously set variables.

4 – assigns the VBA With commands with texts.

5 – executes the VBA Custom Function.

  • Press F5, and you’ll get a draft email to review similar to the below image.

Attached Active Worksheet

Read More: How to Send Multiple Emails from Excel Spreadsheet


Method 4 – Sending an Automatic Email from Excel to Outlook Using the HYPERLINK Function

  • Use the following formula in cell H5.
=HYPERLINK("MailTo:"&C5&"?Subject="&F5&"&cc="&$D$2&"&body="&G5,"Click Here")

The HYPERLINK function takes “MailTo:”&C5&”?Subject=”&F5&”&cc=”&$D$2&”&body=”&G5 as link_location, and “Click Here” as friendly_name.

Hyperlink-Send Automatic Email from Excel to Outlook

  • Hit Enter to paste the link.
  • Click on the link.

Clickable Link

  • Excel takes you to Outlook. You’ll see all the Outlook entries are filled with assigned data from Excel.
  • Click on Send.

Email Draft

  • Drag the Fill Handle to apply the formula to other cells and repeat sending.

Outcome-Send Automatic Email from Excel to Outlook

Read More: How to Send an Editable Excel Spreadsheet by Email


Download the Excel Workbook


Related Articles

<< Go Back To Send Email from Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Maruf Islam
Maruf Islam

MARUF ISLAM is an excellent marine engineer who loves working with Excel and diving into VBA programming. For him, programming is like a superhero tool that saves time when dealing with data, files, and the internet. His skills go beyond the basics, including ABACUS, AutoCAD, Rhinoceros, Maxsurf, and Hydromax. He got his B.Sc in Naval Architecture & Marine Engineering from BUET, and now he's switched gears, working as a content developer. In this role, he creates techy content... Read Full Bio

35 Comments
  1. Is it a way to include attached files using the hyperlink function?

    • Greetings Julian Chen,

      Sadly, the HYPERLINK function doesn’t support any attachment links in its arguments. You have to use Other Means to attach files. You can use Method 3 of this article to include an attachment.

      Regards,
      Md. Maruf Islam (Exceldemy Team)

  2. Hello Maruf,
    I hope your doing well

    Firstly, thanks for the explicit explanation.

    Secondly, I would like to ask how can we include more than one row in the body.

    As I want to send a table within the body mail A1:L2 for example.

    Thanks in advance again.

    • Reply Bishawajit Chakraborty
      Bishawajit Chakraborty Oct 20, 2022 at 1:50 PM

      Hello Rash,
      Thank you for your comment. If you want to send a table within the email body for any range, then you have to create a table in any worksheet. For this, you will follow our Method No.3 where we have used a VBA code to send an active sheet within the email body. Firstly, you can create a table in this active sheet and send this sheet with your table within the email body. Can you please share your Excel file with us? We will customize the file according to your requirements. Email address [email protected].

      Regards,
      Bishawajit Chakraborty (Exceldemy Team)

  3. Hi

    I am trying to create a hyperlink to outlook which can be clicked to send an email with various cell entries. So the cells before the link will have name, number, dates etc, with a first line in the email “Please see below booking” etc and a line at the end “any problems please let me know” etc. When i use the hyperlink function there aren’t enough characters for everything I need in the email, and it puts all the info on one line with no spaces. Is there a way around this? This is the hyperlink formula I have used =HYPERLINK(“Mailto:”&AD5&”?Subject=”&AE5&”&cc=”&AF5&AG5&”&Bcc=”&I4&”&Body=”&AI5&T4&G4&H4&Q4&S4,”EMAIL”)
    The VBA method 2 you have shown looks similar to what I need but without the “IF >2000” addition.
    I have also never attempted VBA before, so I was going to try and copy and paste your VBA and edit it to what I need but I am not that talented just yet!

    Thanks for your help

    • Hello Danielle D, Thank you for your question. For the first question, you can add a line break using the CHAR function. CHAR(10) to be more specific. There are some feature limitations in the HYPERLINK method. You need to use the other methods to do more advanced stuff.

      Then, for the second question, if you send your Excel file to [email protected], we will try to modify the VBA code according to your needs.

  4. Is it possible to send images from excel via e-mail at a specific time every day automatically not manually?

    • Hello Ahmed, thank you for reaching out. You can send email in a certain time of a day automatically, but you have to keep the Excel file open. One more thing, you cannot send email automatically by Excel everyday. You have to set up the time and then run the Macro. The code is given below.

      Option Explicit
      Private Sub Workbook_Open()
      Application.OnTime TimeValue("00:48:00"), "ImageMail"
      End Sub
      Sub ImageMail()
      Dim strEmailAddress As String
      Dim strFirstName As String
      Dim strLastName As String
      Dim appOutlook As Object
      Set appOutlook = CreateObject("Outlook.Application")
      strEmailAddress = "[email protected]"
      Dim mimEmail As Outlook.MailItem
      Dim strPicPath As String
      strPicPath = "C:\Users\DELL\Desktop\blogs\blog 111\how to change bin range in excel histogram (1).png"
      Set mimEmail = appOutlook.CreateItem(olMailItem)
      With mimEmail
      .To = strEmailAddress
      .Subject = "Send Email"
      Dim att As Outlook.Attachment
      Set att = .Attachments.Add(strPicPath, 1, 0)
      .HTMLBody = "<html><h2>Reminder</h2><p>Hello there, here's your solution!</p>" & _
      "<img src=""how to change bin range in excel histogram (1).png""></html>"
      .Send
      End With
      End Sub

      In the picture, I’m providing you some direction regarding where you may need to change the code element.

      Note: If the code doesn’t work, make sure you have an Outlook account and open the Microsoft Office App.

  5. Great post!

  6. I would like to know the VBA or Macro to use on a spreadsheet where I want to email my client but want the email to be one of my Outlook Templates already created. So, if I click on the client’s email address from the spreadsheet or click on a Macro button in the clients contact information row, it launches my Outlook Template filling in the client’s email address and inserts their name at the beginning of the body message.

    Is this possible? I’m struggling to find a video or web pages to show how this is done.

    • Reply Avatar photo
      assign Rubayed Razib Suprov Feb 16, 2023 at 4:39 PM

      Thanks a lot for posting your query in Exceldemy
      Below I am giving you a VBA code using which you can open the outlook template saved on your pc and then replace them with desired text from the Excel sheet.

      
      Sub EmailClient()
          Dim OutApp As Object
          Dim OutMail As Object
          Dim strbody As String
          Dim clientName As String
          
          ' Get the client's email address from the selected cell
          Dim email As String
          email = Selection.Value
          
          ' Get the client's name from the first column of the selected row
          clientName = Cells(Selection.Row, 1).Value
          
          ' Create the email body using your Outlook template
          ' Replace "TemplateName" with the name of your Outlook template
          Set OutApp = CreateObject("Outlook.Application")
          Set OutMail = OutApp.CreateItemFromTemplate("C:\Users\user\Documents\OutlookTemplate.oft")
          
          ' Replace "Client Name" with the name of your client field in the template
          strbody = Replace(OutMail.HTMLBody, "Name", clientName)
          OutMail.HTMLBody = strbody
          
          ' Set the recipient email address
          OutMail.To = email
          
          ' Display the email and let the user edit it before sending
          OutMail.Display
          
          ' Clean up
          Set OutMail = Nothing
          Set OutApp = Nothing
      End Sub
      

      the sample template file that we are using is given below.
      The Name, in the beginning, is going to be replaced by the desired name and the recipient will be the selected mail address.

      In the code, two separate things must be taken seriously, firstly the location of the template file. The location of the template mail has to be specified correctly in the code(Marked as 1), as shown in the image. So please rewrite the location of the file correctly.
      secondly, f you need to specify which term to replace with names inside the code(Marked as 2).

      the location of the template file in your pc can be found in the properties tab as shown below.

      finally, you are ready to execute the code.For this, you have to first select the email address to which you want to send the email. Then Run the Macro by pressing the Macro button placed just right side of the information.

      Then you can see that the a new email has been composed with the name placed in the beginning with the selected mail address as the recipient.

      You can download the sample macro file from the links below
      Sample Macro File: https://www.exceldemy.com/wp-content/uploads/2023/02/Send-Automatic-Email-outlook-template.xlsm\
      In case you need to template file, please contact us through email.
      Regards,
      Rubayed Razib

  7. How to add Attachement in Method 1

    • Reply Avatar photo
      Alif Bin Hussain Mar 9, 2023 at 5:38 PM

      Hello SANJAY DANGI,

      Thank you for reaching out. You can add attachment to the email in the first method easily. Follow these steps to do it.

      • In this example, we want to attach a file named Attachment.pdf. The path directory for the file is D:\Exceldemy\.

      How to Send Automatic Email from Excel to Outlook with Attachment

      • First, download the workbook provided in this article and open it.
      • Next, add a new column (H) and write the file names you want to attach to the email. Make sure to write the file extension.

      How to Send Automatic Email from Excel to Outlook with Attachment

      • Then, open the code module and write the following code.

      Sub ExcelToOutlookSR() Dim mApp As Object Dim mMail As Object Dim SendToMail As String Dim MailSubject As String Dim MailBody As String Dim FileName As String Dim Path As String 'Declare variable for file path Path = "D:\Exceldemy\" 'Set file path For Each r In Selection SendToMail = Range("C" & r.Row) MailSubject = Range("F" & r.Row) MailBody = Range("G" & r.Row) FileName = Range("H" & r.Row) 'Get file name from H column Set mApp = CreateObject("Outlook.Application") Set mMail = mApp.CreateItem(0) With mMail .To = SendToMail .Subject = MailSubject .Body = MailBody .Display .Attachments.Add (Path & FileName) 'Add attachment End With Next r Set mMail = Nothing Set mApp = Nothing End Sub
      How to Send Automatic Email from Excel to Outlook with Attachment

      • After writing this code, go back to the excel sheet.
      • Then, select one or more names and click on the button.

      How to Send Automatic Email from Excel to Outlook with Attachment

      • As a result, Microsoft Outlook software will open and you will find the email already written with the attached file. You can just click send to send the Email.

      How to Send Automatic Email from Excel to Outlook with Attachment

  8. how to include a mail body bigger than 255 characters

    • Reply Avatar photo
      Naimul Hasan Arif Sep 7, 2023 at 12:46 PM

      Hello SAPTARSHI,
      I have personally sent a mail with a mail body of more than 255 characters via the “Using VBA Macro to Automatically Send Email Using Outlook to Selected Recipients” method. The receiver got the mail with the full mail body. I have used Microsoft 365 and found no character restriction in this process.
      Regards,
      Naimul Hasan Arif

  9. Hi, thank you for this super helpful document! I’m wondering whether it is possible to send the email from another account I have from Outlook. It automatically sends it from my personal account but I would like it to send from my second account. Thank you!

    • Reply Abrar-ur-Rahman Niloy
      Abrar-ur-Rahman Niloy Oct 25, 2023 at 12:27 PM

      Hi, Jessica!

      Yes, it is possible. In short, Outlook assigns every email of yours to a number. You can call a specific mail using the Accounts.Item(x) method, x is the number assigned to the mail. Mention this account in the MailItem.SendUsingAccount property and the code will send the mail from that specific account. Keep in mind, the process works for Excel 2007 and later versions.

      Here is the details of the process:

      1. First, check the Microsoft Outlook 15.0 Object Library in VBA editor from the Tools>References>Available References.
        (This is to enable the Outlook library in your Excel workbook)
      2. If you want to find out the numbers associated with each mail, use a code utilizing the Accounts.Item method like the following.
        Sub EmailAccountsList()
        
            Dim OutMail As Outlook.Application
            Dim i As Long
            Dim MailRow As Long
            MailRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
          
            Set OutMail = CreateObject("Outlook.Application")
        
            For i = 1 To OutMail.Session.Accounts.Count
                Sheet1.Cells(MailRow, 1) = OutMail.Session.Accounts.Item(i)
                Sheet1.Cells(MailRow, 2) = i
                MailRow = MailRow + 1
            Next i
        
        End Sub

        This code will give you the list containing your outlook mails and their numbers on your spreadsheet.

      3. Now, use this number in the SendUsingAccount property. Take the first code in this article, for example. In the With statement of mMail, you can modify it like this:
        
        Sub ExcelToOutlookSR()
        Dim mApp As Object
        Dim mMail As Object
        Dim SendToMail As String
        Dim MailSubject As String
        Dim mMailBody As String
        For Each r In Selection
            SendToMail = Range("C" & r.Row)
            MailSubject = Range("F" & r.Row)
            mMailBody = Range("G" & r.Row)
        Set mApp = CreateObject("Outlook.Application")
        Set mMail = mApp.CreateItem(0)
        With mMail
            .To = SendToMail
            .Subject = MailSubject
            .Body = mMailBody
            .SendUsingAccount = mApp.Session.Accounts(2)   'Replace the number in the bracket with your mail number from the previous code's list
            End With
        Next r
        End Sub
        

      Hope this helped. If you still have inquiries, let us know.

      • Hi! I was able to find the number of the account I want to use (2), but when I use the second part of the code, I get the following error message: Runtime error ‘450’ Wrong number of arguments or invalid property assignment. When I click debug, it highlights the “.SendUsingAccount = mApp.Session.Accounts(2)” line of the code. Do you have any idea what went wrong?

  10. Hi there, thanks for the clear explanation. I was wondering whether it is possible to send the emails from my second Outlook account instead of my primary one. Thanks in advance!

    • Reply Abrar-ur-Rahman Niloy
      Abrar-ur-Rahman Niloy Oct 26, 2023 at 9:58 AM

      Hello again, Jessica! In the previous reply, I have mentioned exactly how you can do this. If you go through the second step, you will find the item number of your second Outlook mail (generally is 2. can also be 1 depending on how you had logged in to your accounts).
      If it isn’t, take note of the number. Replace the 2 in .SendUsingAccount = mApp.Session.Accounts(2) with the number Excel shows. You will find this line in the With statement at the end.
      In case if you are having trouble understanding any of the part, let us know about that.

  11. Reply
    Mary Rose Anne Deriquito Dec 21, 2023 at 9:14 PM

    Hi, how can i add signature with below code?

    Sub ExcelToOutlookSR()
    Dim mApp As Object
    Dim mMail As Object
    Dim SendToMail As String
    Dim MailSubject As String
    Dim mMailBody As String
    For Each r In Selection
    SendToMail = Range(“C” & r.Row)
    MailSubject = Range(“F” & r.Row)
    mMailBody = Range(“G” & r.Row)
    Set mApp = CreateObject(“Outlook.Application”)
    Set mMail = mApp.CreateItem(0)
    With mMail
    .To = SendToMail
    .Subject = MailSubject
    .Body = mMailBody
    .Display ‘ You can use .Send
    End With
    Next r
    End Sub

    • Dear Mary,
      You can use the following code that also includes signature.

      
      Sub ExcelToOutlookSR()
          Dim mApp As Object
          Dim mMail As Object
          Dim SendToMail As String
          Dim MailSubject As String
          Dim mMailBody As String
          Dim Signature As String
          
          ' Your signature text goes here
          Signature = "Best regards," & vbCrLf & "Mary Rose"
          
          For Each r In Selection
              SendToMail = Range("C" & r.Row)
              MailSubject = Range("F" & r.Row)
              mMailBody = Range("G" & r.Row) & vbCrLf & vbCrLf & Signature ' Add the signature
              
              Set mApp = CreateObject("Outlook.Application")
              Set mMail = mApp.CreateItem(0)
              
              With mMail
                  .To = SendToMail
                  .Subject = MailSubject
                  .Body = mMailBody
                  .Display ' You can use .Send
              End With
          Next r
      End Sub
      

      Feel free to customize the Signature accordingly.

      Regards
      Aniruddah
      Team Exceldemy

  12. hi, Please advice how to capture the data from pivot in the body of the mail as per the data range in a table format

    • Reply Avatar photo
      Md. Abdur Rahim Rasel Jan 8, 2024 at 4:59 PM

      Hello KARTHIK!
      Thanks for reaching out and sharing your problem with us.
      I think the article will help you capture the data from pivot in the body of the mail as per the data range in a table format. Please read the article again.
      If you are still facing issues, please mail us at the address below.
      [email protected]
      Again, thank you for being with us.
      Regards
      Md. Abdur Rahim Rasel
      Exceldemy Team

  13. Hi there,
    Is there any way to set the From field on an email? I want to hide my own email and send from a generic one. When I try and add .From to the Email set up, I get a 438 error – is there a way around this?

    • Hello Nick Throp,

      The reason of the getting 438 error is you don’t have the on behalf permission. To set the “From” field in an email using VBA in Outlook, you must need to have “Send As” or “Send on Behalf” permissions for the generic email you want to use. Without these permissions, .From property will result in a 438 error.
      To use .From property you should contact to IT admin to obtain the required permissions for the generic email address. Once permissions are granted, the VBA code should work without throwing an error.

      Here’s an example of setting the “From” field:
      MailItem.SentOnBehalfOfName = “[email protected]

      This approach will allow you to send emails on behalf of another account if you get the permission.

      Regards
      ExcelDemy

  14. Hi i am looking to be able to send an automated email when a range of cells are filled in red, and show the information in the email for cells contained in that row, so if a date is past due and cell goes red, any info in the row where the cell turned red is to be contained in the email, i have a basic email going out at the moment

    Thank you

    • Hello Paul,

      You are most welcome. To automate email notifications when a cell turns red, you can update your existing VBA code to check the cell color. You can use the Interior.Color property to identify red cells. Once a red cell is found, compile the data from that row and include it in the email body.

      Sample VBA Code:

      Sub SendEmailOnRedCell()
          Dim rng As Range
          Dim cell As Range
          Dim OutApp As Object
          Dim OutMail As Object
          Dim emailBody As String
          Dim ws As Worksheet
      
          Set ws = ThisWorkbook.Sheets("Sheet1") ' Change to your sheet name
          Set rng = ws.Range("A1:D10") ' Change to your specific range
      
          ' Create Outlook application
          Set OutApp = CreateObject("Outlook.Application")
      
          ' Loop through each cell in the range
          For Each cell In rng
              If cell.Interior.Color = RGB(255, 0, 0) Then ' Check if the cell is red
                  emailBody = "Information from row " & cell.Row & ": " & vbCrLf
                  emailBody = emailBody & "A: " & ws.Cells(cell.Row, 1).Value & vbCrLf
                  emailBody = emailBody & "B: " & ws.Cells(cell.Row, 2).Value & vbCrLf
                  emailBody = emailBody & "C: " & ws.Cells(cell.Row, 3).Value & vbCrLf
                  emailBody = emailBody & "D: " & ws.Cells(cell.Row, 4).Value & vbCrLf
      
                  ' Create and send the email
                  Set OutMail = OutApp.CreateItem(0)
                  With OutMail
                      .To = "[email protected]" ' Change to recipient's email
                      .Subject = "Alert: Red Cell Detected"
                      .Body = emailBody
                      .Send
                  End With
                  Set OutMail = Nothing
              End If
          Next cell
      
          ' Clean up
          Set OutApp = Nothing
      End Sub

      1. This code checks the specified range (A1) in Sheet1 for red cells. If a red cell is found, it compiles information from that row and sends an email.
      2. Remember to update the Range, Sheet name, and recipient email address as needed.
      3. Make sure to enable macros and allow programmatic access to Outlook.

      Regards
      ExcelDemy

  15. Hi Can’t seem to get it to work,

    My work sheet range is A2:O48, to send email once a cell in F turns red.

    Email body info from A and E

    Sub SendEmailOnRedCell()
    Dim rng As Range
    Dim cell As Range
    Dim OutApp As Object
    Dim OutMail As Object
    Dim emailBody As String
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets(“2024 service”) ‘ Change to your sheet name
    Set rng = ws.Range(“A2:O48”) ‘ Change to your specific range

    ‘ Create Outlook application
    Set OutApp = CreateObject(“Outlook.Application”)

    ‘ Loop through each cell in the range
    For Each cell In rng
    If cell.Interior.Color = RGB(255, 0, 0) Then ‘ Check if the cell is red
    emailBody = “Information from row ” & cell.Row & “: ” & vbCrLf
    emailBody = emailBody & “A: ” & ws.Cells(cell.Row, 2).Value & vbCrLf
    emailBody = emailBody & “E: ” & ws.Cells(cell.Row, 2).Value & vbCrLf

    ‘ Create and send the email
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .To = “[email protected]” ‘ Change to recipient’s email
    .Subject = “Alert: Red Cell Detected”
    .Body = emailBody
    .Send
    End With
    Set OutMail = Nothing
    End If
    Next cell

    ‘ Clean up
    Set OutApp = Nothing
    End Sub

    Many thanks for all your help very much appreciated

    • Hello Paul,

      You are most welcome. It looks like there are a couple of issues in your VBA code that need fixing:

      1. The range check should specifically look at column F only.
      2. You need to correct the index for the columns A and E in the email body.

      
      Sub SendEmailOnRedCell()
          Dim rng As Range
          Dim cell As Range
          Dim OutApp As Object
          Dim OutMail As Object
          Dim emailBody As String
          Dim ws As Worksheet
      
          Set ws = ThisWorkbook.Sheets("2024 service") ' Change to your sheet name
          Set rng = ws.Range("F2:F48") ' Check only column F
      
          ' Create Outlook application
          Set OutApp = CreateObject("Outlook.Application")
      
          ' Loop through each cell in column F
          For Each cell In rng
              If cell.Interior.Color = RGB(255, 0, 0) Then ' Check if the cell is red
                  emailBody = "Information from row " & cell.Row & ": " & vbCrLf
                  emailBody = emailBody & "A: " & ws.Cells(cell.Row, 1).Value & vbCrLf ' Column A
                  emailBody = emailBody & "E: " & ws.Cells(cell.Row, 5).Value & vbCrLf ' Column E
      
                  ' Create and send the email
                  Set OutMail = OutApp.CreateItem(0)
                  With OutMail
                      .To = "[email protected]" ' Change to recipient’s email
                      .Subject = "Alert: Red Cell Detected"
                      .Body = emailBody
                      .Send
                  End With
                  Set OutMail = Nothing
              End If
          Next cell
      
          ' Clean up
          Set OutApp = Nothing
      End Sub

      The code now checks only column F (F2) for red cells.
      Corrected the indices for columns A and E (1 for A, 5 for E).

      Regards
      ExcelDemy

  16. Hello, can you please help, i’m really new to this and cant get a email to send when a cell in col f is >=0, email to contain info from col A and col F

    Option Explicit
    Dim Rng As Range
    Sub Worksheet_Change(ByVal mRng As Range)
    On Error Resume Next
    If mRng.Cells.Count > 1 Then Exit Sub
    Set Rng = Intersect(Range(“a2:o48”), mRng)
    If Rng Is Nothing Then Exit Sub
    If IsNumeric(mRng.Value) And Target.Value >= 0 Then
    Call ExcelToOutlook
    End If
    End Sub
    Sub ExcelToOutlook()
    Dim mApp As Object
    Dim mMail As Object
    Dim mMailBody As String
    Set mApp = CreateObject(“Outlook.Application”)
    Set mMail = mApp.CreateItem(0)
    mMailBody = “Hello” & vbNewLine & vbNewLine & _
    “Please note 1 or more items require a service.” & vbNewLine & _
    Range(“a2:f48”) & vbNewLine & vbNewLine & _
    “Regards” & vbNewLine & _
    “Outlet Team”
    On Error Resume Next
    With mMail
    .To = “[email protected]
    .CC = “”
    .BCC = “”
    .Subject = “”
    .Body = mMailBody
    .Display ‘or you can use .Send
    End With
    On Error GoTo 0
    Set mMail = Nothing
    Set mApp = Nothing
    End Sub

    • Hello Paul,

      You can use this updated VBA code that will send an email when a cell in column F is >= 0 and include information from columns A and F in the email body.
      Option Explicit Dim Rng As Range Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next ' Check if more than one cell is changed If Target.Cells.Count > 1 Then Exit Sub ' Limit the range to A2:O48 Set Rng = Intersect(Me.Range("A2:O48"), Target) If Rng Is Nothing Then Exit Sub ' Check if the cell in column F is >= 0 If Not IsNumeric(Target.Value) Then Exit Sub If Target.Column = 6 And Target.Value >= 0 Then Call SendEmail(Target.Row) End If End Sub Sub SendEmail(rowNum As Long) Dim mApp As Object Dim mMail As Object Dim mMailBody As String Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("2024 service") ' Change to your sheet name Set mApp = CreateObject("Outlook.Application") Set mMail = mApp.CreateItem(0) ' Prepare email body with info from column A and F mMailBody = "Hello," & vbNewLine & vbNewLine & _ "Please note that item in row " & rowNum & " requires attention." & vbNewLine & _ "A: " & ws.Cells(rowNum, 1).Value & vbNewLine & _ "F: " & ws.Cells(rowNum, 6).Value & vbNewLine & _ vbNewLine & "Regards," & vbNewLine & "Outlet Team" ' Send email On Error Resume Next With mMail .To = "[email protected]" ' Change to recipient’s email .Subject = "Alert: Cell in Column F >= 0" .Body = mMailBody .Display ' or you can use .Send to send the email directly End With On Error GoTo 0 ' Clean up Set mMail = Nothing Set mApp = Nothing End Sub
      Worksheet_Change Event triggers when any cell in the range A2 changes. Sends an email when a cell in column F is greater than or equal to 0. Includes the information from columns A and F for the corresponding row in the email body.

      Regards
      ExcelDemy

  17. Hi really sorry, I cant work out the individual lines of text where 1 starts and ends?

    • Hello Paul,

      Each line of the email body starts and ends with vbNewLine for formatting. The _ at the end of each line allows you to split longer lines across multiple lines for readability. You can follow this breakdown to understand how each line flows.

      ' Build the email body with info from column A and F
          mMailBody = "Hello," & vbNewLine & vbNewLine & _    ' First line of email
                      "Please note that item in row " & rowNum & " requires attention." & vbNewLine & _   ' Mention row number
                      "A: " & ws.Cells(rowNum, 1).Value & vbNewLine & _    ' Include column A value in email
                      "F: " & ws.Cells(rowNum, 6).Value & vbNewLine & _    ' Include column F value in email
                      vbNewLine & "Regards," & vbNewLine & "Outlet Team"    ' Closing the email
          
          ' Send the email using Outlook
          On Error Resume Next
          With mMail
              .To = "[email protected]"   ' Recipient's email
              .Subject = "Alert: Cell in Column F >= 0"   ' Email subject
              .Body = mMailBody   ' Email body containing row info
              .Display   ' Use .Send to send directly without preview
          End With

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo