Kutools for Excel 22.00 HOT

300+ Powerful Features You Must Have in Excel

Kutools-for-Excel

Kutools for Excel is a powerful add-in that frees you from performing time-consuming operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful features / functions for Excel 2019, 2016, 2013, 2010, 2007 or Office 365!

Read More Download Buy now

Office Tab 14.00HOT

Adding Tabbed Interface for Office

Office Tab

It enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. It's compatible with Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365. Demo

Read More Download Buy now

Kutools for Outlook 13.00NEW

100+ Powerful Features for Outlook

Kutools-for-Outlook

Kutools for Outlook is a powerful add-in that frees you from time-consuming operations which majority of Outlook users has to perform daily! It can save your time from using Microsoft Outlook 2019, 2016, 2013, 2010 or Office 365!

Read More Download Buy now

Kutools for Word  9.00NEW

100+ Powerful Features for Word

Kutools-for-Word

Kutools for Word is a powerful add-in that frees you from time-consuming operations which majority of Word users have to perform daily! It can save your time from using Microsoft Word / Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365!

Read More Download Buy now

Classic Menu for Office

Bringing Back Your Familiar Menus

Restores the old look and menus of Office 2003 to Microsoft Office 2019, 2016, 2013, 2010, 2007 or Office 365. Don’t lose time in finding commands on the new Ribbon. Easy to deploy to all computers in enterprises and organizations.

Read More Download Buy now

How to automatically send email based on cell value in Excel?

Supposing you want to send an email through Outlook to a certain recipient based on a specified cell value in Excel. For example, when the value of cell D7 in a worksheet is greater than 200, then an email is created automatically. This article introduces a VBA method for you to quickly solve this issue.

Automatically send email based on cell value with VBA code


Automatically send email based on cell value with VBA code

Please do as follows to send an email based on cell value in Excel.

1. In the worksheet you need to send email based on its cell value (here says the cell D7), right-click the sheet tab, and select View Code from the context menu. See screenshot:

2. In the popping up Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the sheet code window.

VBA code: Send email through Outlook based on cell value in Excel

Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
  Set xRg = Intersect(Range("D7"), Target)
    If xRg Is Nothing Then Exit Sub
    If IsNumeric(Target.Value) And Target.Value > 200 Then
        Call Mail_small_Text_Outlook
    End If
End Sub
Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2"
    On Error Resume Next
    With xOutMail
        .To = "Email Address"
        .CC = ""
        .BCC = ""
        .Subject = "send by cell value test"
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Notes:

1. In the VBA code, D7 and value > 200 are the cell and cell value you will send email based on.

2. Please change the email body as you need in xMailBody line in the code.

3. Replace the Email Address with the recipient email address in line .To = "Email Address".

4. And specify the Cc and Bcc recipients as you need in .CC = “” and Bcc = “” sections.

5. Finally change the email subject in line .Subject = "send by cell value test".

3. Press the Alt + Q keys together to close the Microsoft Visual Basic for Applications window.

From now on, when the value you entering in cell D7 is greater than 200, an email with specified recipients and body will be created automatically in Outlook. You can click the Send button to send this email. See screenshot:

Notes:

1. The VBA code is only working when you use Outlook as your email program.

2. If the entered data in cell D7 is a text value, the email window will be popped out as well.


Easily send email through Outlook based on fields of created mailing list in Excel:

The Send Emails utility of Kutools for Excel helps users sending email through Outlook based on created mailing list in Excel.
Download and try it now! ( 30-day free trail)


Related articles:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Ian · 1 years ago
    Hello!


    I'm new to VBA, so this may be a dumb question. I'm trying to use this code to send automatic email alerts when inventory gets below a numerical value that is specific to each cell. I've been able to get it to work for one cell, and now I'm trying to repeat the process for other cells in my sheet. (i.e. When D7 get's below 2 it send out an email. But when D8 gets below 4 I'd like it to send out a different email.)However, copying and pasting the code and changing the specified cell does not work. What can I do to solve this problem? Thanks!
  • To post as a guest, your comment is unpublished.
    Kim · 1 years ago
    I have a code to autogenerate an email if an change is made to cells e11:a33. If I make several changes, I'd only like it to autogenerate the email once. How can I do this? Thanks,


    Dim xRg As Range
    'Update by Extendoffice 2018/3/7
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Determine if change was made to cells E11:E33
    If Not Intersect(Target, Range("E11:E33")) Is Nothing Then
    Call Mail_small_Text_Outlook
    End If
    End Sub
    Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "LAC team," & vbNewLine & vbNewLine & _
    "This LAC Event Management Macro for _ has a status update. Please review. Thanks."
    On Error Resume Next
    With xOutMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "Event Planning Update"
    .Body = xMailBody
    .Display 'or use .Send
    End With
    On Error GoTo 0

    Set xOutMail = Nothing
    Set xOutApp = Nothing
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Kim,
      Sorry I am not sure I got your question. Would be nice if you could provide screenshot of what you are trying to do.
      Or you can post any question about Excel to our forum: https://www.extendoffice.com/forum.html to get more Excel supports from our professional or other Excel fans.
  • To post as a guest, your comment is unpublished.
    hiba · 1 years ago
    I have a list of email addresses in excel that i need to send emails to The subject and body are in cells besides the email address and i have the script below but i need to send 100 emails per 1 hour how i can please your support

    Sub SendEm()
    Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    Set Mail_Object = CreateObject("Outlook.Application")
    For i = 2 To lr
    With Mail_Object.CreateItem(o)
    .Subject = Range("B" & i).Value
    .To = Range("A" & i).Value

    .Body = Range("C" & i).Value
    .attachments.Add (Sheets("Sheet1").Range("H" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("I" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("J" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("K" & i).Text)
    .Send

    '.display 'disable display and enable send to send automatically
    End With
    Next i
    MsgBox "E-mail successfully sent", 64
    Application.DisplayAlerts = False
    Set Mail_Object = Nothing
    End Sub
  • To post as a guest, your comment is unpublished.
    hiba · 1 years ago
    I have a list of email addresses in excel that i need to send emails to The subject and body are in cells besides the email address and i have the script below but i need to send 100 emails per 1 hour how i can please your support

    Sub SendEm()
    Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    Set Mail_Object = CreateObject("Outlook.Application")
    For i = 2 To lr
    With Mail_Object.CreateItem(o)
    .Subject = Range("B" & i).Value
    .To = Range("A" & i).Value

    .Body = Range("C" & i).Value
    .attachments.Add (Sheets("Sheet1").Range("H" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("I" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("J" & i).Text)
    .attachments.Add (Sheets("Sheet1").Range("K" & i).Text)
    .Send

    '.display 'disable display and enable send to send automatically
    End With
    Next i
    MsgBox "E-mail successfully sent", 64
    Application.DisplayAlerts = False
    Set Mail_Object = Nothing
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Sorry can’t help you with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
  • To post as a guest, your comment is unpublished.
    Akbar · 1 years ago
    I have a requirement to send over 30 email. I have two sheet wherein in sheet1 the data is there and I create 30 individual worksheet with name.

    Below are conditions:-


    1. Each workbook will be send as a separate email.
    2. Each email will have different recipient for To, which is there in H7 and CC
    3. Each email will have same subject based on workbook/worksheet name.
    4. Each email will have same body based on worksheet Name & month.


    Now, a table can be made in excel which will list all points from 1-4 in different columns as a master data table. I can achieve this part.


    Can there be a macro which can read this table and create separate emails by adding attachments from a path?
  • To post as a guest, your comment is unpublished.
    Louis · 1 years ago
    Hi


    The email is working. The problem i have is that i would like to send the mail ones it is saved and the value is < 200
    if value is > 200 then no email should go out.
    i have 10 values to change and every time i change a value the calculated value sends a mail
    so i would like to make it ( <200 AND save ) then email should be generated.


    Thanks
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Louis,
      If you want to make it (<200 AND save), here you need to apply three VBA codes in your workbook.

      1. Please insert a Module and rename it as "UpdataVBA_2", then copy below VBA code 1 into the Module window.

      VBA code 1.
      Public mBolSendMail As Boolean

      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub

      2 Copy the below VBA code 2 into the ThisWorkbook code window

      VBA code 2:
      Private Sub Workbook_AfterSave(ByVal Success As Boolean)
      If UpdataVBA_2.mBolSendMail Then
      Call Mail_small_Text_Outlook
      End If
      mBolSendMail = False
      End Sub

      Private Sub Workbook_Open()
      UpdataVBA.mBolSendMail = False
      End Sub

      3. Now you need to copy the following code into the worksheet code window your specific cell locates in.
      VBA code 3:
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xPRg As Range
      Dim xRRg As Range
      On Error Resume Next
      Set xRRg = Range("D7")
      If Target.Cells.count > 1 Then Exit Sub
      Set xRg = Intersect(xRRg, Target)
      If xRg Is Nothing Then
      Set xPRg = xRRg.Precedents
      Set xRg = Intersect(xPRg, Target)
      If xRg Is Nothing Then Exit Sub
      End If
      If IsNumeric(xRRg) And xRRg.Value < 200 Then
      UpdataVBA_2.mBolSendMail = True
      'Call Mail_small_Text_Outlook
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Jarvis Head · 1 years ago
    I have a worksheet where 60 different values could change, prompting 5 different emails. How do I write the code to look at each individual change and then send the corresponding email? Thanks for the assistance
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Sorry can’t help you with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
  • To post as a guest, your comment is unpublished.
    S.Balasubramanian · 1 years ago
    Vendor ID Order no Part qty pending
    abc@gmail.com 6542684 apple 78 45
    abc@gmail.com 8786854 orange 45 0
    def@gmail.com 651654 Letter 1245 148
    def@gmail.com 898882 cover 547 65

    from the above excel sheet data

    i have to send mail to abc@gmail.com and def@gmail.com with their respective line

    condition is "pending" value should be greater than 0

    Guide me how to do it
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      Please try the below VBA code, hope it can help. Thanks for your comment.

      Dim xRg As Range
      Private Sub Worksheet_Change(ByVal Target As Range)
      On Error Resume Next
      If Target.Cells.Count > 1 Then Exit Sub
      For Each xRg In Range("E2:E5")
      If CInt(xRg.Value) > 0 Then
      Call Mail_small_Text_Outlook
      End If
      Next
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xIntR As Integer
      xIntR = xRg.Row
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "ID Order no. :" & Range("B" & xIntR).Value & vbNewLine & _
      "Part :" & Range("C" & xIntR).Value & vbNewLine & _
      "Qty :" & Range("D" & xIntR).Value & vbNewLine
      On Error Resume Next
      With xOutMail
      .To = Range("A" & xIntR).Value
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Kennedy · 1 years ago
    I have the code running correctly for when a cell within a range of cells drops below a 1.The problem is that the cells I am referencing use a formula. And when a value that is part of the formula is changed and the cell referenced in the code drops below 1, an email is not sent. The email will only be prompted when the cell itself is changed. How do I code for this?


    Thanks
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Kennedy,
      The following VBA code can help you solve the problem. Please don't forget to replace the "Email Address" with the recipient's email address in the code. Thank you.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRgPre As Range
      On Error Resume Next
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Range("D7")
      Set xRgPre = xRg.Precedents
      If xRg.Value > 200 Then
      If Target.Address = xRg.Address Then
      Call Mail_small_Text_Outlook
      ElseIf (Not xRgPre Is Nothing) And (Intersect(Target, xRgPre).Address = Target.Address) Then
      Call Mail_small_Text_Outlook
      End If
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
      • To post as a guest, your comment is unpublished.
        xami4p@gmail.com · 1 years ago
        Hi Crystal,
        Thank you for the code. I was trying to use your code to send an email notification. The challenge is however, I have values in column F7 to F300 (some of the cells are blank in column F) which are formulas calculating the remaining days to certain deadlines. So, everyday the values in column F will decrease by 1. I would like to get a notification email where there are only 7 days left to the deadlines. Also, in the xMailBody, I would like to have texts referencing from the excel spreadsheet (like the project name which is going to be due and in how many days). Can this reminder email work even when excel is not running?
        I would appreciate very much your time if you kindly help me to solve the issue.
        Regards,
        Rahman
  • To post as a guest, your comment is unpublished.
    wu · 2 years ago
    Hi.

    I am wondering whether it is possible to tailor the first line of each email. For example, in my excel sheet I have a column with title such as Mr., a column with last name such as Black.
    I want to send out emails automatically with the first line: Dear Mr. Black
    for the others the first line will be accordingly dear ms. White....etc..


    Will that be possible to change the wording in the body of the email. That is my issue here.


    Thanks a lot
  • To post as a guest, your comment is unpublished.
    ExcelEnthusiast · 2 years ago
    I have a requirement to send over 50 email. Below are conditions:-


    1. Each workbook will be send as a separate email.
    2. Each email will have different recipient for To, CC and BCC.
    3. Each email will have different subject based on workbook/worksheet name.
    4. Each email will have different body based on date & subject.


    Now, a table can be made in excel which will list all points from 1-4 in different columns as a master data table. I can achieve this part.


    Can there be a macro which can read this table and create separate emails by adding attachments from a path?


    This will be a great help and save tremendous amount of time.
  • To post as a guest, your comment is unpublished.
    justin.p.patterson@gmail.com · 2 years ago
    I have a worksheet that has about 20 columns of data, but I only have two that I want to focus on here. Column D is lot number and Column Z is priority. I would like excel to send and email when Column Z has a priority of “HOT” and send an email including the associated lot number in Column D. It will either be HOT or blank so nothing needs to be done unless it is HOT. I would like the Email to go to about 5 people and say something along the lines of “Hello Team, Lot “xxxx’s” Priority has changed to HOT, please prioritize this lot.


    Is it possible to have it look up the lot number associated to the priority and place it in the text like that. If not maybe have the subject of the email be the associated lot number and then have the text just be as it was without the lot number.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Patterson,
      The below VBA code can help you solve the problem. Please have a try. Thank you for your comment.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range
      On Error Resume Next
      If (Target.Count > 1) Then Exit Sub
      Set xRg = Intersect(Target, Range("Z:Z"))
      If xRg Is Nothing Then Exit Sub
      If UCase(Target.Value) = "HOT" Then
      Call Mail_small_Text_Outlook(Target)
      End If
      End Sub
      Sub Mail_small_Text_Outlook(ByVal xCell As Range)
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hello Team" & vbNewLine & vbNewLine & _
      "Lot " & Range("D" & xCell.Row) & "'s Priority has changed to HOT, please prioritize this lot."
      On Error Resume Next
      With xOutMail
      .To = "Email Address1; Email Address2; Email Address3; Email Address4; Email Address5"
      .CC = ""
      .BCC = ""
      .Subject = "Lot number is " & Range("D" & xCell.Row)
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Vignesh · 2 years ago
    I am trying to mail the content which is present in A1:G5 columns in excel ,but its not working. Can you help me with that?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Vignesh,
      The following VBA code can help you solve the problem. Thank you for your comment.

      Dim xRg As Range
      Private Sub Worksheet_Change(ByVal Target As Range)
      On Error Resume Next
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Intersect(Range("D7"), Target)
      If xRg Is Nothing Then Exit Sub
      If IsNumeric(Target.Value) And Target.Value > 200 Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim I, J As Long
      Dim xRg As Range
      Dim xStr As String
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      Set xRg = Range("A1:G5")
      For I = 1 To xRg.Rows.Count
      For J = 1 To xRg.Columns.Count
      xStr = xStr & xRg.Rows(I).Cells(J) & " "
      Next
      xStr = xStr & vbNewLine
      Next
      xMailBody = "Hi there" & vbNewLine & vbNewLine & xStr
      On Error Resume Next
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Vetrak · 2 years ago
    I would like to ask if it is possible to send one email when closing the application - each change means a large number of emails.


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If (Not Intersect(Target, Range("B2:B9")) Is Nothing) And (Target.Value < 3) Then
    Call Mail_small_Text_Outlook
    End If
    End Sub
    Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Ahoj," & vbNewLine & vbNewLine & _
    "xxx." & vbNewLine & _
    ""
    On Error Resume Next
    With xOutMail
    .To = "xxx"
    .CC = ""
    .BCC = ""
    .Subject = "xxx"
    .Body = xMailBody
    .Send 'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
    End Sub


    Thank you
  • To post as a guest, your comment is unpublished.
    Pavel · 2 years ago
    Hello
    I would like to ask if it is possible to send one email when closing the application - each change means a large number of emails.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If (Not Intersect(Target, Range("B2:B9")) Is Nothing) And (Target.Value < 3) Then
    Call Mail_small_Text_Outlook
    End If
    End Sub
    Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Ahoj," & vbNewLine & vbNewLine & _
    "XXX." & vbNewLine & _
    ""
    On Error Resume Next
    With xOutMail
    .To = "1234"
    .CC = ""
    .BCC = ""
    .Subject = "XXX"
    .Body = xMailBody
    .Send 'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hello Pavel,
      Would you explain it in more details? I don't really get your point, sorry about that.
  • To post as a guest, your comment is unpublished.
    fifi · 2 years ago
    hello, can u help me
    1. send this email with attach the worksheet
    2. set timer automatically send this email weekly (like every sunday)


    thanks
  • To post as a guest, your comment is unpublished.
    jason · 2 years ago
    hello, sir: may i ask how to display the value in D7 in the out bouncing email automatically ?
    thanks
    jason
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Jason,
      The following VBA code can help you solve the problem. Thank you.

      Dim xRg As Range
      'Update by Extendoffice 2018/5/22
      Private Sub Worksheet_Change(ByVal Target As Range)
      On Error Resume Next
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Intersect(Range("D7"), Target)
      If xRg Is Nothing Then Exit Sub
      If IsNumeric(Target.Value) And Target.Value > 200 Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2 " & vbNewLine & "value is " & xRg.Value
      On Error Resume Next
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    kevin b · 2 years ago
    Hello- If I wanted to send to an email from a list instead of putting actual email addy in the code, is that possible? thanks
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hello,
      Please try below VBA code, when the specified cell meets the condition, a dialog will pop up, please select the cell contains the email address you will sent email to. Hope it can help. Thank you.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Range("D7")
      If xRg = Target And Target.Value > 200 Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xRgMsg As Range
      Dim xCell As Range
      Set xRgMsg = Application.InputBox("Please select the address cells:", "Kutools for Excel", , , , , , 8)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      For Each xCell In xRgMsg
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      With xOutMail
      .To = xCell.Value
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      xOutApp = Nothing
      xOutMail = Nothing
      Next
      On Error GoTo 0
      End Sub
  • To post as a guest, your comment is unpublished.
    basha · 2 years ago
    hi crystal
    thanks for your codes, if possible kindly send the codes for below given details

    if we have 8 to 9 coloums using different type of expires like passport expiry date, driving licence expiry date, vehicle registration expiry date, gate pass expiry date and more etc., and mail alert must send to only 5 given persons.

    like our date sheet is with more than 300 employees, expired and expiry date with in 15 days in red colour and email alert should sent.

    kindly do the needful

    thanks in advance
  • To post as a guest, your comment is unpublished.
    alely · 2 years ago
    So I used your edit to include a cell ranges but (if we are using the worksheet example) I was wondering how to add the type of fruit, the Date, and the quantity into the HTML email from the worksheet if they fit the criteria to have an email generated. So it would say

    "Hi there,"

    Fruit name from cell "Needs to be put on back order because as of order date: " order date from cell "we have this amount:" quantity from cell.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Noemi,
      Please try this VBA scrip.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range
      Dim I, J, K As Long
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      On Error Resume Next
      If Target.Address = Range("D7").Address Then
      With Application.WorksheetFunction
      If IsNumeric(Target.Value) And Target.Value > 200 Then
      Set xRg = Application.InputBox("Please select the cell range you will display in the mail body:", "KuTools for Excel", Selection.Address, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      For I = 1 To xRg.Rows.Count
      For J = 1 To xRg.Rows(I).Columns.Count
      For K = 1 To xRg.Rows(I).Columns(J).Count
      xMailBody = xMailBody & " " & xRg.Rows(I).Columns(J).Cells(K).Text
      Next
      Next
      xMailBody = xMailBody & vbNewLine
      Next
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = "Hi there " & vbNewLine & xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End If
      End With
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Jan · 2 years ago
    Hi,
    I would like Outlook to pop out only when the data I have pasted into the Range ("D7:F7") has at least 1 zero or a blank.
    I have removed the 'If Target.Cells.Count > 1 Then Exit Sub' line and now Outlook always launches when i paste any group of values into cells D7:F7.

    Help.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Jan,
      The following script can help you solve the problem. Thank you for your comment.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      On Error Resume Next
      If Target.Address = Range("D7:F7").Address Then
      With Application.WorksheetFunction
      If .CountIf(Target, "") > 0 Or .CountIf(Target, 0) > 0 Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = "Hi there "
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End If
      End With
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Jesse · 2 years ago
    Hi,


    What if I wanted to send the email based off of the word "completed" being added to column L?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Jesse,
      The following VBA code can help you solve the problem. Thank you for your comment.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      If (Not Intersect(Target, Range("L:L")) Is Nothing) And (Target.Value = "completed") Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Your recipient's email address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Moorhen · 2 years ago
    Hi there,


    I currently having a little trouble this the coding (new to this - may have bitten off more than I can chew)


    I currently have a spreadsheet with the following that I need help to automate and send email for fault that are at our properties for our business


    I currently need a code that will do use the following data:


    1) An address and the issue ( 2 "general" cells that have been merged via ((In cell D1)) " = =CONCAT(B1," "C1,) "
    The address in B1 will allways be same (more or less)
    Whilst C1 will always be changing dependant on the fault at the property.


    2) An email to be sent by the same email adress, ( can I use $E$1 or I have to use E1 - E1 . for example) or can I just Input " TheEmailAdress@.co.uk" in the line of code


    3) The email body to be populated in the similar way to point 1) ...... ((In cell F1)) " =CONCAT(G1," ",H1)
    These will be changing constantly as they represent the company (G1) and what they are doing , fixing, quoting ect (H1)

    4) The trigger to send the email off, I would be the number 7 , the sheet gets updated daily (7 days in a week)
    as such I need the trigger to send the email on day 7, but no constantly like on day 8, 9 , 10+ ect. and not before such as 1-6, this would be in A4 : A 100+ (as we are constantly expanding


    4) I've used small snippets from other users who mentioned about using a list for the trigger to send the email, but not sure was 100 % it was correct, but i'd need it to scan though all Collum A.... A4: A100
    and if there are 47 cells that contain only " 7 " then 47 Emails will be sent


    Thank you ever so much for reading and I hope you can help :)
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear martyn,
      Sorry can't help with this.
      You can post your question in our forum: https://www.extendoffice.com/forum.html to get more Excel supports from our technical staff.
      Thank you for your comment.

      Best Regards,
      Crystal
  • To post as a guest, your comment is unpublished.
    MC · 2 years ago
    Hi

    Thank you so much for posting this VBA Code and instructions. When I found it I felt like I had won the lotto. However I am stuck on something so I'm hoping you can help (I'm new to VBA, only have very basic understanding).

    I've copied the code and changed the cell and cell value to pick from a range if a criteria is met. I have tried and tested and it works and I received an email to outlook based on the criteria.

    1) However, I cannot seem to figure out how to get the VBA code to run automatically when I open up the excel worksheet, rather than having to click on the VBA application and select run. Could you advise if there is an additional prompt to type into the VBA code above that will do this or does it have to be done separately.

    2) Also is there a way to get the VBA code to send a mail to a person if the due date is yes for a certain item as shown in example below.
    email hidden column
    Name

    Procedure
    Procedure no.1 due date yes
    Procedure no. 2 due date no

    I would have numerous people in the spreadsheet (going across horizontally in a row) and 'Yes' could be highlighted for various overdue procedures (listed vertically in column A. Is there a way to create a VBA code that runs for something like this - if 'Yes' for 'Person 1', then email 'person 1' with 'procedure no #' (or numbers) and due date(s). Being able to list in the email all the procedures and their subsequent due dates.

    I wouldn't mind if I had to set a separate VBA code for each person as long as it sent a mail of all the documents overdue for that person and the due dates.

    Hoping you can help
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Ann,
      Please try the below VBA code. Thank you for your comment.

      Sub Mail_small_Text_Outlook()
      Dim xRg As Range
      Dim xCell As Range
      Dim I As Long
      Dim xRows As Long
      Dim xCols As Long
      Dim xVal As String
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      On Error Resume Next
      Set xRg = Application.InputBox("Select the range contains the cell value you will send emails based on:", "Kutools for Excel", Selection.Address, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      xRows = xRg.Rows.Count
      xCols = xRg.Columns.Count
      For I = 1 To xRows
      Set xCell = xRg(I, xCols)
      If xCell.Value = "Yes" Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is your information: " & vbNewLine & xCell.Offset(0, -1).Text & vbNewLine & xCell.Offset(0, -2).Text
      With xOutMail
      .To = xCell.Offset(0, -4).Text
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End If
      Next
      End Sub
      • To post as a guest, your comment is unpublished.
        Jacob · 2 years ago
        Where exactly do we insert this code?
        • To post as a guest, your comment is unpublished.
          crystal · 2 years ago
          Good day,
          You need to place the code into the worksheet's code window.
          Open the Microsoft Visual Basic for Applications window, double click the sheet name in the left pane to open the code editor.
      • To post as a guest, your comment is unpublished.
        Jermaine · 2 years ago
        Crystal,

        This replaces the following code:

        Sub email()

        Dim xRg As Range

        Dim xRgEach As Range

        Dim xEmail_Subject, xEmail_Send_Form,;etc.
  • To post as a guest, your comment is unpublished.
    hanizah223@gmail.com · 2 years ago
    how to stop code from running ie don't prompt the email when condition is not met?

    even when D7 < 200, I still get prompted the email.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good Day,
      The code is updated in the post with the problem solved. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Savy · 2 years ago
    How can you add Multiple Range to "Set xRg = Range("D7")". I want to edit it and add Range("D7:F7"). However i am getting an error of Run Time Error 13, Type Mismatch and it is taking me to If xRg = Target And Target.Value > 2 Then.


    How can i solve this proble?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good Day,
      Please try below VBA code to solve the problem.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      If (Not Intersect(Target, Range("D7:F7")) Is Nothing) And (Target.Value > 200) Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Your recipient's email address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
      • To post as a guest, your comment is unpublished.
        Nitol · 1 years ago
        It is not working for me as the value in D7 is a result of a formual. What if cell D7 contains a formula, e.g. D7 =2*120? It still meets the condition but nothing is happening. Please help
      • To post as a guest, your comment is unpublished.
        Savy · 2 years ago
        worked perfectly fine.. Thank you..:):)
  • To post as a guest, your comment is unpublished.
    Doug · 2 years ago
    How can I edit the code to send an email based on a date in the cell. For example, I need a document reviewed every 15 months and I want to kick out an email at 12 months to an email address saying the document needs to be reviewed. I've got it now to auto-send an email by changing .Display to .Send and it works great as written, but what do I need to change to use a date function instead of a whole number??
  • To post as a guest, your comment is unpublished.
    New2Excel · 2 years ago
    Hello what code would I use if I am trying to send an email to a manager that has a list of the fruit that has a quantity > 200 once per month (based on your example) or expires soon( based on dates)
  • To post as a guest, your comment is unpublished.
    vj.mayank@gmail.com · 2 years ago
    I am having trouble sending mail through outlook. I receive the error saying "A program is trying to send an email on your behalf. If it is unexpected, please deny and verify your anti-virus software is up to date"
    Please help as I am not able to automate it.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Sorry mayank,
      The code works well in my case. It seems that something about "send on behalf" function is configured in your Outlook. Pease check for it.
  • To post as a guest, your comment is unpublished.
    Dhruv · 2 years ago
    I have a list of email addresses already in an excel file, how can I modify the code to automatically choose the email address of the person if his cell D7 is >200?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good Day,
      The following VBA code can help you solve the problem. Please place the VBA script into your worksheet module. When value in the specified cell meet the condition, a Kutools for Excel dialog box will pop up, please select the cells which contain the recipients' email addresses and then click the OK button. Then emails with specified recipients are opening. Please send them as you need.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Range("D7")
      If xRg = Target And Target.Value > 200 Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xRgMsg As Range
      Dim xCell As Range
      Set xRgMsg = Application.InputBox("Please select the address cells:", "Kutools for Excel", , , , , , 8)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      For Each xCell In xRgMsg
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      With xOutMail
      .To = xCell.Value
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      xOutApp = Nothing
      xOutMail = Nothing
      Next
      On Error GoTo 0
      End Sub
  • To post as a guest, your comment is unpublished.
    fdh1201 · 2 years ago
    How could I change this code for sending student grades to parents. Where if column A is the grade and Column B is the parent email. I want to populate an email for each student with an F as a grade.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Frank,
      The below VBA code can help you solve the problem. Thank you.

      Sub Mail_small_Text_Outlook()
      Dim xRg As Range
      Dim I As Long
      Dim xRows As Long
      Dim xVal As String
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      On Error Resume Next
      Set xRg = Application.InputBox("Please select grade column and the email column (two columns)", "Kutools for Excel", Selection.Address, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      xRows = xRg.Rows.Count
      Set xRg = xRg(2)
      For I = 1 To xRows
      xVal = xRg.Offset(I, -1).Text
      If xVal = "F" Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is your child's grade " & xRg.Offset(I, -1).Text
      With xOutMail
      .to = xRg.Offset(I, 0).Text
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End If
      Next
      End Sub
  • To post as a guest, your comment is unpublished.
    Jose Manuel · 2 years ago
    Hello, how would you modify this code to check wether a group of cells have the string "No match" and send an email if it has.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Jose,
      Please try below VBA code. When running the code, a dialog box pops up, please select the range you will check for string, and click the OK button. if the string does not exist, you will get a prompt dialog box. If the string exists in the range, an email with specified recipient, subject and body will display.

      Sub SendEmail()
      Dim I As Long
      Dim J As Long
      Dim xRg As Range
      Dim xArr
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xFlag As Boolean
      On Error Resume Next
      Set xRg = Application.InputBox("Please select range", "Kutools for Excel", Selection.Address, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      xArr = xRg.Value
      xFlag = False
      For I = 1 To UBound(xArr)
      For J = 1 To UBound(xArr, 2)
      If xArr(I, J) = "No Match" Then
      xFlag = True
      End If
      Next
      Next
      If xFlag Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      With xOutMail
      .To = "Email address"
      .CC = ""
      .BCC = ""
      .Subject = "Match"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      Else
      MsgBox "Found No matched value", vbInformation, "KuTools for Excel"
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    basil · 2 years ago
    Hi I put the same script but it is not working please help me in the 1st part

    Dim xRg As Range

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRg = Range("D7")
    If xRg = Target And Target.Value = 200 Then
    Call Mail_small_Text_Outlook
    End If

    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear basil,
      Is there any warning when running the code?
  • To post as a guest, your comment is unpublished.
    Brahma · 2 years ago
    will it be sent automatically mail, without any manual interruption
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Brahma,
      If you want to directly send the email without displaying, please replace the line ".Display" with ".Send" in the above VBA code.
  • To post as a guest, your comment is unpublished.
    Shawn Henry · 2 years ago
    Hello

    I am having trouble because Email recipient has to be added again and again one by one. Please guide if list of email recipients can be added to this function so the the function will select the email address from the list of email addresses provided or list upload and the function sends the email, already composed to the desired recipient.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Henry,
      The following VBA code can help you solve the problem. Please place the VBA script into your worksheet module. When value in the specified cell meet the condition, a Kutools for Excel dialog box will pop up, please select the cells which contain the recipients' email addresses and then click the OK button. Then emails with specified recipients are opening. Please send them as you need.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Range("D7")
      If xRg = Target And Target.Value > 200 Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xRgMsg As Range
      Dim xCell As Range
      Set xRgMsg = Application.InputBox("Please select the address cells:", "Kutools for Excel", , , , , , 8)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      For Each xCell In xRgMsg
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      With xOutMail
      .To = xCell.Value
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      xOutApp = Nothing
      xOutMail = Nothing
      Next
      On Error GoTo 0
      End Sub
  • To post as a guest, your comment is unpublished.
    Jordan · 2 years ago
    I am having trouble getting this code to prompt if the value in the cell is changed indirectly. For example, if I have Sum equation changing this value automatically. When the equation runs and the value goes above the set value to prompt the email, it does not do so, unless I physically change the number myself. Is there a way to make the email prompt even if changed indirectly?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Jordan,
      The following VBA code can help you solve the problem. Please don't forget to replace the "Email Address" with the recipient's email address in the code. Thank you.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRgPre As Range
      On Error Resume Next
      If Target.Cells.Count > 1 Then Exit Sub
      Set xRg = Range("D7")
      Set xRgPre = xRg.Precedents
      If xRg.Value > 200 Then
      If Target.Address = xRg.Address Then
      Call Mail_small_Text_Outlook
      ElseIf (Not xRgPre Is Nothing) And (Intersect(Target, xRgPre).Address = Target.Address) Then
      Call Mail_small_Text_Outlook
      End If
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
      • To post as a guest, your comment is unpublished.
        Jim · 1 years ago
        I used this code with the only change being I have applied it to an entire column [Set xRg = Range("D4:D13")]. Now the event triggers whenever a calculation is made regardless of whether the valve in Column D is below the target value. Any idea's why that is?


        Dim Xrg As Range
        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim xRgPre As Range
        On Error Resume Next
        If Target.Cells.Count > 1 Then Exit Sub
        Set Xrg = Range("D4:D13")
        Set xRgPre = Xrg.Precedents
        If Xrg.Value < 1200 Then
        If Target.Address = Xrg.Address Then
        Call Mail_small_Text_Outlook
        ElseIf (Not xRgPre Is Nothing) And (Intersect(Target, xRgPre).Address = Target.Address) Then
        Call Mail_small_Text_Outlook
        End If
        End If
        End Sub

        Sub Mail_small_Text_Outlook()
        Dim xOutApp As Object
        Dim xOutMail As Object
        Dim xMailBody As String
        Set xOutApp = CreateObject("Outlook.Application")
        Set xOutMail = xOutApp.CreateItem(0)
        xMailBody = "Hi" & vbNewLine & _
        "Test vba" _
        & vbNewLine & _
        "Line 2."
        On Error Resume Next
        With xOutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Auto Email Test"
        .Body = xMailBody
        .Display
        End With
        On Error GoTo 0
        Set xOutMail = Nothing
        Set xOutApp = Nothing

        End Sub


        Thanks.
      • To post as a guest, your comment is unpublished.
        Herrera5238 · 2 years ago
        I've modified suggested code to try to make it work for my application.
        Changed xRg = Range("C2:C40") and If xRg.Value = -1.

        The issue that I'm having is anytime there is a change to any cell and as long as one of the cells in my range is = -1 it will call Mail_small_Text_Outlook.
        I'm trying to only call if any cell in my range is changed indirectly to -1.
        I was also wondering if and how it would be possible to have it meet two criteria.
        Like check range A and range B and if they meet criteria call function.

        Thanks in advance for the help. I'm new to all this but reading through this thread has me about 90% there.


        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim xRgPre As Range
        On Error Resume Next
        If Target.Cells.Count > 1 Then Exit Sub
        Set xRg = Range("C2:C40")
        Set xRgPre = xRg.Precedents
        If xRg.Value = -1 Then
        If Target.Address = xRg.Address Then
        Call Mail_small_Text_Outlook
        ElseIf (Not xRgPre Is Nothing) And (Intersect(Target, xRgPre).Address = Target.Address) Then
        Call Mail_small_Text_Outlook
        End If
        End If
        End Sub
  • To post as a guest, your comment is unpublished.
    Debbie · 2 years ago
    How should the code be modified, to apply to an entire range of cells?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Debbie,
      Please try below VBA code to solve the problem.

      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Cells.Count > 1 Then Exit Sub
      If (Not Intersect(Target, Range("A1:D4")) Is Nothing) And (Target.Value > 200) Then
      Call Mail_small_Text_Outlook
      End If
      End Sub
      Sub Mail_small_Text_Outlook()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      On Error Resume Next
      With xOutMail
      .To = "Your recipient's email address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub

Feature Tutorials