วิธีส่งอีเมลโดยอัตโนมัติตามค่าเซลล์ใน Excel
สมมติว่าคุณต้องการส่งอีเมลผ่าน Outlook ไปยังผู้รับบางรายตามค่าเซลล์ที่ระบุใน Excel ตัวอย่างเช่นเมื่อค่าของเซลล์ D7 ในแผ่นงานมากกว่า 200 อีเมลจะถูกสร้างขึ้นโดยอัตโนมัติ บทความนี้แนะนำวิธีการ VBA เพื่อให้คุณแก้ไขปัญหานี้ได้อย่างรวดเร็ว
ส่งอีเมลโดยอัตโนมัติตามค่าเซลล์ด้วยรหัส VBA
ส่งอีเมลโดยอัตโนมัติตามค่าเซลล์ด้วยรหัส VBA
โปรดทำดังนี้เพื่อส่งอีเมลตามค่าเซลล์ใน Excel
1. ในแผ่นงานคุณต้องส่งอีเมลตามค่าของเซลล์ (ในที่นี้คือเซลล์ D7) คลิกขวาที่แท็บแผ่นงานแล้วเลือก ดูรหัส จากเมนูบริบท ดูภาพหน้าจอ:
2. ในการโผล่ขึ้นมา Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดคัดลอกและวางโค้ด VBA ด้านล่างลงในหน้าต่างรหัสแผ่นงาน
รหัส VBA: ส่งอีเมลผ่าน Outlook ตามค่าเซลล์ใน 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
หมายเหตุ:
1. ในรหัส VBA D7 และ มูลค่า> 200 เป็นเซลล์และค่าเซลล์ที่คุณจะส่งอีเมลตาม
2. โปรดเปลี่ยนเนื้อหาอีเมลตามที่คุณต้องการ xMailBody บรรทัดในรหัส
3. แทนที่ที่อยู่อีเมลด้วยที่อยู่อีเมลของผู้รับในบรรทัด . ถึง = "ที่อยู่อีเมล".
4. และระบุผู้รับ Cc และ Bcc ตามที่คุณต้องการ .CC =“” และ สำเนาลับ =“” ส่วน
5. สุดท้ายเปลี่ยนหัวข้ออีเมลในบรรทัด .ubject = "ส่งโดยการทดสอบค่าเซลล์".
3 กด อื่น ๆ + Q เข้าด้วยกันเพื่อปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง
จากนี้ไปเมื่อค่าที่คุณป้อนในเซลล์ D7 มากกว่า 200 อีเมลที่มีผู้รับและเนื้อหาที่ระบุจะถูกสร้างขึ้นโดยอัตโนมัติใน Outlook คุณสามารถคลิกไฟล์ ส่ง เพื่อส่งอีเมลนี้ ดูภาพหน้าจอ:
หมายเหตุ:
1. รหัส VBA จะใช้งานได้ก็ต่อเมื่อคุณใช้ Outlook เป็นโปรแกรมอีเมลของคุณ
2. หากข้อมูลที่ป้อนในเซลล์ D7 เป็นค่าข้อความหน้าต่างอีเมลจะปรากฏขึ้นเช่นกัน
ส่งอีเมลผ่าน Outlook ได้อย่างง่ายดายตามช่องของรายชื่อผู้รับจดหมายที่สร้างขึ้นใน Excel
แพทเทิร์น ส่งอีเมลล์ ประโยชน์ของ Kutools สำหรับ Excel ช่วยให้ผู้ใช้ส่งอีเมลผ่าน Outlook ตามรายชื่อผู้รับจดหมายที่สร้างขึ้นใน Excel
ดาวน์โหลดและทดลองใช้เลย! (เส้นทางฟรี 30 วัน)
บทความที่เกี่ยวข้อง:
- วิธีส่งอีเมลผ่าน Outlook เมื่อบันทึกสมุดงานใน Excel
- จะส่งอีเมลได้อย่างไรหากมีการแก้ไขเซลล์บางเซลล์ใน Excel
- จะส่งอีเมลได้อย่างไรหากคลิกปุ่มใน Excel
- จะส่งอีเมลได้อย่างไรหากตรงตามวันที่ครบกำหนดใน Excel
- วิธีส่งอีเมลเตือนความจำหรือการแจ้งเตือนหากมีการอัปเดตสมุดงานใน Excel
เครื่องมือเพิ่มประสิทธิภาพการทำงานในสำนักงานที่ดีที่สุด
Kutools สำหรับ Excel ช่วยแก้ปัญหาส่วนใหญ่ของคุณและเพิ่มผลผลิตของคุณได้ถึง 80%
- นำมาใช้ใหม่: ใส่อย่างรวดเร็ว สูตรที่ซับซ้อนแผนภูมิ และสิ่งที่คุณเคยใช้มาก่อน เข้ารหัสเซลล์ ด้วยรหัสผ่าน; สร้างรายชื่อผู้รับจดหมาย และส่งอีเมล ...
- Super Formula Bar (แก้ไขข้อความและสูตรหลายบรรทัดได้อย่างง่ายดาย); การอ่านเค้าโครง (อ่านและแก้ไขเซลล์จำนวนมากได้อย่างง่ายดาย); วางลงในช่วงที่กรองแล้ว...
- ผสานเซลล์ / แถว / คอลัมน์ โดยไม่สูญเสียข้อมูล แยกเนื้อหาของเซลล์ รวมแถว / คอลัมน์ที่ซ้ำกัน... ป้องกันเซลล์ซ้ำ; เปรียบเทียบช่วง...
- เลือกซ้ำหรือไม่ซ้ำ แถว; เลือกแถวว่าง (เซลล์ทั้งหมดว่างเปล่า); Super Find และ Fuzzy Find ในสมุดงานจำนวนมาก สุ่มเลือก ...
- สำเนาถูกต้อง หลายเซลล์โดยไม่เปลี่ยนการอ้างอิงสูตร สร้างการอ้างอิงอัตโนมัติ ถึงหลายแผ่น ใส่สัญลักษณ์แสดงหัวข้อย่อย, กล่องกาเครื่องหมายและอื่น ๆ ...
- แยกข้อความ, เพิ่มข้อความ, ลบตามตำแหน่ง, ลบ Space; สร้างและพิมพ์ผลรวมย่อยของเพจ แปลงระหว่างเนื้อหาของเซลล์และความคิดเห็น...
- ซุปเปอร์ฟิลเตอร์ (บันทึกและใช้โครงร่างตัวกรองกับแผ่นงานอื่น ๆ ); การเรียงลำดับขั้นสูง ตามเดือน / สัปดาห์ / วันความถี่และอื่น ๆ ตัวกรองพิเศษ โดยตัวหนาตัวเอียง ...
- รวมสมุดงานและแผ่นงาน; ผสานตารางตามคอลัมน์สำคัญ แยกข้อมูลออกเป็นหลายแผ่น; Batch แปลง xls, xlsx และ PDF...
- คุณสมบัติที่ทรงพลังมากกว่า 300 รายการ. รองรับ Office / Excel 2007-2019 และ 365 รองรับทุกภาษา ใช้งานง่ายในองค์กรหรือองค์กรของคุณ ทดลองใช้ฟรี 30 วันเต็ม รับประกันคืนเงิน 60 วัน

แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก
- เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
- เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
- เพิ่มผลผลิตของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!

You are guest
or post as a guest, but your post won't be published automatically.
-
To post as a guest, your comment is unpublished.· 13 days agoHi, could anyone help I'm trying to send emails to a different address when a name is entered into a particular cell do I need to adjust this code or have a new piece of code for each address i.e if cell = AA then send to AA@hotmail.com or if cell = BB then send to BB@hotmail.com etc.
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Hi, I've been able to create an email with content, but now I'm trying to extract data from a specified cell related to the initial query. How do I get that data to show in the email Body with the below code? I've tried linking with a vLookUp function to extract that data. So basically, how do I get in the main example above, "This is line 1" to show the Data being pulled for xData below
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 2017/9/12
Dim xRgSel As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xMailBody As String
Dim xData As Object
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xRg = Range("J:J")
Set xRgSel = Intersect(Target, xRg)
Set xData = Application.WorksheetFunction.VLookup(xRgSel, Range("Data_Table"), 6, False)
ActiveWorkbook.Save
If Not xRgSel Is Nothing Then
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xMailBody = xData & "Cell(s) " & xRgSel.Address(False, False) & _
" in the worksheet '" & Me.Name & "' were modified on " & _
Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
" by " & Environ$("username") & " in https://textmgmt.sharepoint.com/:x:/r/sites/EmailManagedServiceCollaboration/Documents/(%20Test)%20Shared%20TM%20Tracking%20Document%20-%20Local%20Email%20Campaign.xlsm?d=w7ad2f1404d574b9abb529ec248453f42&csf=1&web=1&e=zg9REc ."
With xMailItem
.To = "jason.thompson@textmanagement.co.uk"
.Subject = "Worksheet modified in Brand Approve Column "
.Body = xMailBody
.Send
End With
Set xRgSel = Nothing
Set xOutApp = Nothing
Set xMailItem = Nothing
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
-
To post as a guest, your comment is unpublished.Hi, I am stuck with a piece of Code. I have combined a few comments below but can't get it to workI have added the xtarget part of the code in the Mail_small_text_Outlook to select a specific cell to be included as subjectAs a result, nothing works anymore. Could someone help pleaseDim 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("AC9"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value = 1 Then
ActiveSheet.Calculate
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook(xTarget As Range)
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim xR
xR = xTarget.Row
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = ""
On Error Resume Next
With xOutMail
.To = "email"
.CC = ""
.BCC = ""
.Subject = Cells(xR, 1).Value
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("AC9")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI = 1 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub -
To post as a guest, your comment is unpublished.Good day,
Thank you for teaching me something new, I am trying to get excel to send out an email to different sales reps.
So if row X is an error code of "999" then it needs to send an email to the rep I placed the email addresses in row K as it differs for every line, but if row X is "0" it should not send an email.
is this possible? -
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Thank you for the fantastic VBA coding, i am learning quite a bit. As I am a little "green" with this skill, i am currently trying to have the macro choose between doing nothing, or sending one of two different email to send based on a cell value. If the cell has noting in it then "do nothing", if the cell has a "1" or a "2" in it choose either "Mail_small_Text_Outlook()" or "Mail_small_Text_Outlook_2()". I can not figure this out and i am reaching out to see if there are some brighter minds that could help me with this.Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("N5"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value = 1 Then
Call Mail_small_Text_Outlook
Exit Sub
ElseIf IsNumeric(Target.Value) And Target.Value = 2 Then
Call Mail_small_Text_Outlook_2
Exit Sub
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 = "" & vbNewLine & vbNewLine & _
On Error Resume Next
With xOutMail
' .SentOnBehalfOfName = ""
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Sub Mail_small_Text_Outlook_2()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "" & vbNewLine & vbNewLine & _
On Error Resume Next
With xOutMail
' .SentOnBehalfOfName = ""
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("N5")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI = 1 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub -
To post as a guest, your comment is unpublished.helloi want to send automatic emails when due date come to the concern departments.i have to apply this to 3 or 4 columnscan you please send me code
-
To post as a guest, your comment is unpublished.Good day,The method in below article may do you a favor. Please have a look:How To Send Email If Due Date Has Been Met In Excel?
-
-
To post as a guest, your comment is unpublished.Hello,If for example a cell in column D is filled in to meet the criteria to auto generate an email. Can this be adapted to pull the information from the row in which has been filled in.ie D7 is filled in so email the contents of A7, B7, C7ie D25 is filled in so email the contents of A25, B25, C25Thanks
-
To post as a guest, your comment is unpublished.Hi Ckey1990,The below code can do you a favor, please have a try. Thank you.Dim xRg As Range 'Update by Extendoffice 2020/8/28 Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next If Target.Cells.Count > 1 Then Exit Sub Set xRg = Intersect(Range("D:D"), Target) If xRg Is Nothing Then Exit Sub If Target.Value = "Done" Then Call Mail_small_Text_Outlook(Target) End If End Sub Sub Mail_small_Text_Outlook(xTarget As Range) Dim xOutApp As Object Dim xOutMail As Object Dim xMailBody As String Dim xR xR = xTarget.Row Set xOutApp = CreateObject("Outlook.Application") Set xOutMail = xOutApp.CreateItem(0) xMailBody = "Hi there" & vbNewLine & vbNewLine & _ Cells(xR, 1).Value & vbNewLine & _ Cells(xR, 2).Value & vbNewLine & _ Cells(xR, 3).Value & vbNewLine 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.I posted before and got a great answer...but moving forward i need more info. I have coulmn "C" listed with 25 different emails. I have column "D" "E" & "F" used for date completions (ex. August 17 = 081720). I need the email body to be different for each of the DEF cells but only go to ONE email in that coresponding row once entered
D3..(EMAIL A) to c3 address, E3(EMAIL B) to c3 address, F3 (EMAIL C) to c3 address
D4..(EMAIL A) to c4 address, E4(EMAIL B) to c4 address, F4 (EMAIL C) to c4 address...
Does this make sense?
-
To post as a guest, your comment is unpublished.Thank you for the code, this code works when I enter the value and press enter. But in my case the cell is filling automatically with formula, and when the value is reached it doesn't open the email (the code do not works in this case). I would also like the email body to populate data from the other cells for that line item how would I get it to pull that cell data in reference to the cell that created the email?Any help would be fantastic!
-
To post as a guest, your comment is unpublished.Hi Mladen,
I can only help to solve the formula problem for you. Please have a try. Thank you!
Dim xRg As Range
'Update by Extendoffice 2020/08/21
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
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("D7")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI > 200 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub
-
-
To post as a guest, your comment is unpublished.Hi !
I have managed to get the coding up and running. However I would like to have the "from" fix from one of my accounts. Several people will be creating this autoresponse so I need to have a fixed "from"
Thank you in advance!-
To post as a guest, your comment is unpublished.Hi Thais,
The email will be sent with the default account in your Outlook. If you need a fixed "from", please get into the account settings dialog in your Outlook, and then specify the account as the default one.-
To post as a guest, your comment is unpublished.Hi Crystal!Thank you for the tip :-)The issue is that the code for sending the email is on a shared excel. People who mighty choose to send the automated email from this shared excel, are most often not the ones who might be able to answer if someone replies to the automated email. Therefore I would like the automated email to always be from a fixed email, in that way we avoid peopel who send the automated email to get questions. Do you know if this can be fixed? I mean, in the code you can choose the to: and subject:, shouldnt we be able to design the :from?
-
To post as a guest, your comment is unpublished.Hi Thais,I got your point. It just like sending an email on behalf of someone.Please add the below line to the code, and don't forget to specify the email address. (After running the code, you will see the From field has a fixed email address).SentOnBehalfOfName = "Email Address"The whole VBA code is as follows.Dim xRg As Range 'Update by Extendoffice 20120/8/28 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 .SentOnBehalfOfName = "Email Address" .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.Thank you for the code ! I'm having a small issue where the code will only select the first cell that meets my criteria
( I want to flag any tasks that are late so were due before the current date, however the code is only taking the first value and not all the values in my excle"
the following is my code, i would be forever grateful if you could help!
Public Sub Late_Task_Email()
'Updated by Extendoffice 2018/11/22
Dim xRgDate As Range
Dim xRgSend As Range
Dim xRgText As Range
Dim xRgDone As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xLastRow As Long
Dim vbCrLf As String
Dim xMailBody As String
Dim xRgDateVal As String
Dim xRgSendVal As String
Dim xMailSubject As String
Dim xStrRang As String
Dim i As Long
On Error Resume Next
Set xRgDate = Range("F12:F500")
Set xRgDate = Range(xStrRang)
Set xRgSend = Range("B12:B500")
Set xRgSend = Range(xStrRang)
Set xRgText = Range("A12:A500")
Set xRgText = Range(xStrRang)
xLastRow = xRgDate.Rows.Count
Set xRgDate = xRgDate(1)
Set xRgSend = xRgSend(1)
Set xRgText = xRgText(1)
Set xOutApp = CreateObject("Outlook.Application")
For i = 1 To xLastRow
xRgDateVal = ""
xRgDateVal = xRgDate.Offset(i - 1).Value
If xRgDateVal <> "" Then
If CDate(xRgDateVal) - Date < 0 Then
xRgSendVal = xRgSend.Offset(i - 1).Value
xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
vbCrLf = "
"
xMailBody = ""
xMailBody = xMailBody & "Dear DOE,"
xMailBody = xMailBody & "This task is OVERDUE!"
xMailBody = xMailBody & ""
Set xMailItem = xOutApp.CreateItem(0)
With xMailItem
.Subject = xMailSubject
.To = xRgSendVal
.HTMLBody = xMailBody
.Display
'.Send
End With
Set xMailItem = Nothing
End If
End If
Next
Set xOutApp = Nothing
End Sub
-
To post as a guest, your comment is unpublished.
-
-
To post as a guest, your comment is unpublished.Hi Crystal, thank you for sharing this awesome code! I changed the code to function with text so when a cell has anything typed in, it prompts the email function. My question is, how can I code the email to auto-populate the row and column header info for a specific cell along with text? Here are the ranges of data with text:
Subject "(A3:A50) - (Q1:AC1) - Pending"
Mail Body "(P1:AB1) complete."
"Please prepare the (Q1:AC1)"
'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("P3:AB50"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value > 0 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 = "Hello," & vbNewLine & vbNewLine & _
"Create Bid Comparison step complete." & vbNewLine & _
"Please prepare the Recommendation of Award." & vbNewLine & vbNewLine & _
"Thank you"
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ("Project 20-20")
.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.To better clarify, I am hoping to auto-populate the column and row headers into the email, along with text.
Subject "(A3:A50) - (Q1:AC1) - Pending"
Mail Body "(P1:AB1) complete."
"Please prepare the (Q1:AC1)"
(i.e. C12, the headers for the subject line would be A12 and C1. C12 for the 1st line in the "Mail Body" and D12 for the 2nd.)
This way, any cell I enter data into will prompt the email and pull the headers in pertaining to that cell.
Thank you!
-
-
To post as a guest, your comment is unpublished.Hello
I need a help. I use VB code for automatically to send email based on cell value in Excel. The thing is that this code works when I enter the value and press enter. But in my case the cell is filling automatically with formula, and when the value is reached it doesn't open the email (the code do not works in this case). Ex.
-
To post as a guest, your comment is unpublished.Hey Crystal,
I'd like to set automatic emails based on drop options of Update Request, Complete or More Info in Cell I. Update Request will send an email to three different email addresses and Complete or More Info will send an email to one email address. Also, how do to I write each Range to equal data that corresponds to the row with the drop down option.
My data below only triggers off Update Request for a specific range (b3). Help!
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("I:I"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value = "Update Request" 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 = "All," & vbNewLine & vbNewLine & _
"Updates have been entered into the maintenance log:" & vbNewLine & _
Range("b3") & vbNewLine & _
Range("c3") & vbNewLine & _
Range("d3") & vbNewLine & vbNewLine & _
"Thanks," & vbNewLine & _
"Training Team"
With xOutMail
.To = "ShondaX@yahoo.com"
.CC = ""
.BCC = ""
.Subject = "Log Update Requests"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Thanks, Shonda -
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Is there a way to send emails to individual recipients that can be pulled from another cell in the same row?
-
To post as a guest, your comment is unpublished.Hi Tyson nold,
Supposing the recipient's email address is in F7, please apply the below code.
Dim xRg As Range
'Update by Extendoffice 2020/7/17
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 = Range("F7")
.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.That only pulled the information for that cell. If you are only sending one email for the D7 cell this works but how do you get it to change to another cell for the next value in column D? As in if the next value over 200 is D10 how do you get the email to auto pull the information from F10 instead of F7? That's the issue I'm running into right now.Thank you!
-
To post as a guest, your comment is unpublished.
-
-
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.I want my email to send when any of the cells in row H are changed to a specific value, which is one of 3 drop down options (Ready for Inventory) set for that row. How do I modify this coding to that instead of a manually entered value? Thanks!!
-
To post as a guest, your comment is unpublished.Hi Brittany,
Supposing there are drop down lists in column H, and you want to trigger an email when selecting "Done" from the drop-down, please try the below VBA to get it down.
Dim xRg As Range
'Update by Extendoffice 2020/6/12
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("H:H"), Target)
If xRg Is Nothing Then Exit Sub
If Target.Value = "Done" 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
-
To post as a guest, your comment is unpublished.HelloI need a help. I use VB code for automatically to send email based on cell value in Excel. The thing is that this code works when I enter the value and press enter. But in my case the cell is filling automatically with formula, and when the value is reached it doesn't open the email (the code do not works in this case).
-
To post as a guest, your comment is unpublished.Hi Mladen,
Try the below code.
Dim xRg As Range
'Update by Extendoffice 2012/08/07
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
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("D7")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI > 200 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.This is great but I need it to pull information from other cells on the same row that is triggering the email... Can anyone help?
-
-
-
To post as a guest, your comment is unpublished.
-
-
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Cystal,
This is definitely a time saver. I want to know what I would have to add to the vba to include my signature line on the outgoing email. On my usual emails, I have a signature line with company logo and contact info. I want to include that so the email looks just like it would if I had sent myself manually from Outlook. Many thanks!
Mike-
To post as a guest, your comment is unpublished.Hi darkgyft.
Try the below VBA code. Hope I can help. thank you.
Dim xRg As Range
'Update by Extendoffice 2020/05/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)
On Error Resume Next
With xOutMail
.Display 'or use .Send
.To = "Email Address"
.CC = ""
.BCC = ""
.Subject = "send by cell value test"
.HTMLBody = "This is a test email sending in Excel" & "
" & .HTMLBody
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
-
-
To post as a guest, your comment is unpublished.Hi - I tried to use the code, it works fine when cell value D7 is changed manually. if D7 value changed using any formula i.e vlookup or IF .code doesnt trigger. Code trigger only when any cell on the sheet is change keeping D7 value above 200. is there any wayout for the problem . regards srini
-
To post as a guest, your comment is unpublished.Hi,
The below VBA code can help you solve the problem. Please have a try. Thank you.
Dim xRg As Range
'Update by Extendoffice 20120/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"
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
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("D7")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI > 200 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub
-
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Hi all - I am trying to use this code but when I exit the developer and test the cell- it is over the specifications, but nothing happens. I don't receive a pop up to send the email? But when I run the code in developer it comes up - its just when I'm within the spreadsheet and change the cell, nothing happens. I have copied and edited the code as per instructions.
-
To post as a guest, your comment is unpublished.Dear all kindly help me …… my requirement as follow..!!
I will be having a workbook in which there will be set of data
then i'll be manually entering a date as a value in a cell
when the actual date matches with my manual entered date
excel has to automatically trigger a mail in OUTLOOK with so and so data along with a body of letter to recipient and also cc
thanks a lot in advance -
To post as a guest, your comment is unpublished.How can I refer to a cell on the worksheet to include in the email automatically?
-
To post as a guest, your comment is unpublished.Hi Robert,
Supposing you want to refer to cell A7 on the worksheet, please apply the below code.
Dim xRg As Range
'Update by Extendoffice 2019/12/13
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 Rng = Selection.SpecialCells(xlCellTypeVisible)
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
Range("A7") & vbNewLine & _
"Best Regards"
On Error Resume Next
With xOutMail
.To = ""
.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.Crystal you're the best.
I want to download the data to be checked with a SQL query, what do I have to do to make the code below work then, at the moment it only works manually.
Thank you
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.Crystal you're the best.
what do i have to add to make the code work with formulas ?
Thank you
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("B:B"))
If xRg Is Nothing Then Exit Sub
If UCase(Target.Value) = "Yes" 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("A" & xCell.Row) & "'s Priority has changed to Yes, 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("A" & 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.I need help with Excel to send an automatic email using outlook when a cell value is changed in the file.
Question . Sheet name "Attrition Report" Column L in the file has the list of RAG status, So, when one of the manager will choose the options (Green, Red, Amber) for possible attrition cases. When the cell value changes to Red or Amber ; excel should automatically send an email ONLY when it changes to RED or Amber. The body of the email should show employee name which is in Cell range "B" and the RAG status which is in Range "L".
I put the code but i guess it's incorrect.
Any help on this will be much appreciated.
Thanks and Regards
Emanuel Prasanna Kumar
The code i currently have. is.
_______________
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("L2:L100")
If CInt(xRg.Value) = "Red" And "Amber" 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 & _
"Emp Name. :" & Range("B" & xIntR).Value & vbNewLine & _
"RAG Status :" & Range("L" & xIntR).Value & vbNewLine & _
"Factor :" & Range("K" & xIntR).Value & vbNewLine
On Error Resume Next
With xOutMail
.To = "Emanuel.Kumar@infovision.com"
.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.How can I display the Sheet name and list of cells which has value more than 200 in the email content?
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.Hi All,
Can someone help me to figure out the below
I have an Excel sheet with loads of worksheets in it.
Data is entered in 3 worksheets on daily basis and information from these 3 sheets is sent out to mailing list on every Sunday (data accumulated from Last Sunday to Saturday in those 3 work sheets).
This XL sheet is stored in share point. -
To post as a guest, your comment is unpublished.Hi Crystal,
Thank you for this code. It is extremely helpful. I am trying to add a few things to it and was wondering if you or someone following this post could help.
How can you add Cell Text from the same Range (row) to the Mail Body?
How can you get the code to send an email for every Cell in the Range that is over an amount?
Thank you so much! -
To post as a guest, your comment is unpublished.Hi Crystal,
Thank you for your extremely useful posts! I have the VBA code working perfectly for our purposes, except for one problem - when I open the workbook or make a change, each email is created twice. What can be done to ensure each email is only created once?
Many thanks, Rob
My current code:
Dim xRg As Range
'Update by Extendoffice 2019/8/2
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("A1"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value = 1 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 = "Dear " & Range("C3") & "," & vbNewLine & vbNewLine & _
"I am writing to inform you that the Form D filing for " & Range("C2") & " is due on " & Range("C4") & ". All securities offerings that rely on the exemptions set forth under Regulation D are required to file a Form D every year for as long as the offering is open." & vbNewLine & vbNewLine & _
"It is advised that " & Range("C2") & " should maintain its Form D filing if it continues to offer securities in reliance on Regulation D. Maintaining an up-to-date Form D is important in ensuring compliance with federal and state securities regulations." & vbNewLine & vbNewLine & _
"Please let us know at your earliest convenience if you wish to arrange the renewal of the Form D." & vbNewLine & vbNewLine & _
"Thank you," & vbNewLine
On Error Resume Next
With xOutMail
.To = Range("C5")
.CC = "t.kim@geracillp.com"
.BCC = ""
.Subject = "Form D filing notice for " & Range("C2")
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("A1")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI = 1 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub-
To post as a guest, your comment is unpublished.Actually, more to the point - how do I make it so that only one email is created when I open the workbook, but not just when I make a change to it? Currently changing any cell results in a new email being created.
Please help with this last hurdle, I'm so close!
-
-
To post as a guest, your comment is unpublished.
-
To post as a guest, your comment is unpublished.I Keep Getting this:
Run-time error '429':
ActiveX component can't create object
I use apple and don't have outlook... is there a way to make this work without outlook.. and
instead Mail Version 11.5 (3445.9.1) apple -
To post as a guest, your comment is unpublished.Thank you for posting valuable and important VBA code. I am new in VBA coding and trying to modify your VBA with editing Mail Body;
...
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
...
How to add Cell Text Ex. text from A7, B7 & C7 related to D7 into Mail Body instead of other text. Could someone please guide me. Thank you in advance.-
To post as a guest, your comment is unpublished.Hi Ganesh,
Please apply the below code. Hope I can help.
Dim xRg As Range
'Update by Extendoffice 2019/12/13
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 & _
Range("A7") & vbNewLine & _
Range("B7") & vbNewLine & _
Range("C7") & vbNewLine & _
"Best Regards"
On Error Resume Next
With xOutMail
.To = ""
.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.I have the exact situation but only difference is ...I have got around 100 rows to check. So it has to check each row on column D if any cell on column D meets the criteria it has to add info from column A B and C for respective D cell and after checking all 100 rows it has to send one email.
-
-
-
To post as a guest, your comment is unpublished.I have another question, how do you write in VBA so instead of "If IsNumeric(Target.Value) And Target.Value > 200 Then" (detecting a value greater than 200 it detects any text input..... for example in cell D7 you write any words (not number but words) it calls out the email ! please respond
-
To post as a guest, your comment is unpublished.Hi
I got a question, on excel I have a column with several emails written (they are formulated), for example A36 is example1@hotmail.com, A37 is example2@hotmail.com, A38 is example3@hotmail.com, I want that the part of the programming VBA To: Range (A36:A38) so they send the email to each of those wroten emails, the thing is that I put it like this To: Range (A36:A38) but it does not work, am I doing it wrong?-
To post as a guest, your comment is unpublished.Hi ricardo suarez,
The below VBA code can solve your problem. Please have a try and thank you for your comment.
Dim xRg As Range
'Update by Extendoffice 2019/8/14
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
For Each cell In Range("A36:A38")
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next cell
If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
Application.ScreenUpdating = False
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 = strto
.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.Hi
My vba code works fine, even the email part to outlook. I'm quite chuffed as I am a novice at vba. I created an automated process to create an invoice and email in pdf.
However the next step is I want to include a status on the excel spreadsheet, which is my database to say "complete" or "sent". I'm thinking maybe an IF formula? I don't want to use a message box. Basically I just want to keep record that for each creditor the email has been sent.
How would I do that in VBA
Thanks for your help:) -
To post as a guest, your comment is unpublished.Hi. I am trying to use your code and I get the email but I want the email address I have in cell E159 to pop up as the email address. I also want to Display a cell value in the middle of my email. I have tried several ways and none seem to work. I cannot use the kudotools app. I only have excel and the vba.
-
To post as a guest, your comment is unpublished.Hi Roxiann,
Supposing you want to send email to address in cell E159, and display value of cell A1 in your email body, you can try the below VBA code. Thanks for your comment.
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 & _
Range("A1") & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = Range("E159")
.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.Hi Crystal, thanks for the last answer, i got a quick question, how can i add the cell value automatically to the mailbody
-
To post as a guest, your comment is unpublished.Or just include this line Range("D7") & vbNewLine & _ in the xMailBody line.
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
Range("D7") & vbNewLine & _
"This is line 2"-
To post as a guest, your comment is unpublished.Thank you very much ! Crystal
-
-
To post as a guest, your comment is unpublished.Hi Otoniel,
Supposing the cell D7 is in the worksheet named "Sheet2", please change the xMailBody line in above code to
xMailBody = "The value of D7 is" & ThisWorkbook.Sheets("Sheet2").Cells(7, 4).Value
Don't forget to change the sheet name and the cell number as you need (here Cells(7,4) represents cell D7 which locationg in row 7 column 4).
-
-
To post as a guest, your comment is unpublished.This is great but just the last step is not completing my request. Could you please update so it automatically sends out the email, without clicking send.
-
To post as a guest, your comment is unpublished.I am having a similar issue as has been brought up, the VBA works with manually values. I have 2 workbooks, I hope to pull data from workbook 2 into workbook1. Workbook 1 then subtracts 2 numbers, one of which is pulled from workbook2 (via using formula of =value in cell in workbook 2). Then if the difference is less than a given number, I hope to send an email. When I manually enter the number the VBA works great. When I use the = value of cell in workbook 2, VBA does not run. I feel so close but still out of arms length. Any help is greatly appreciated. Thanks much.
-
To post as a guest, your comment is unpublished.Hello is it possible, that instead of popping up the email.
Can it be configured to automatically send the mail, without the need to send it manually? -
To post as a guest, your comment is unpublished.Is there was a way to prompt the email by cells that are populated by a formula? This seems to only work when populating the cells manually. Thanks!
-
To post as a guest, your comment is unpublished.Good day,
The below VBA code will do you a favor.
Dim xRg As Range
'Update by Extendoffice 2019/8/2
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
Private Sub Worksheet_Calculate()
Dim xI As Integer
Dim xRg As Range
Set xRg = Range("D7")
On Error GoTo Err01
xI = Int(xRg.Value)
If xI > 200 Then
Call Mail_small_Text_Outlook
End If
Err01:
End Sub
-