Good day,
please see attached document, I want Excel to send an automatic email to each rep for each line that has 999 error code (in Yellow), please help...
Good day,
please see attached document, I want Excel to send an automatic email to each rep for each line that has 999 error code (in Yellow), please help...
Yolani
Further to the discussion above, please try the attached file (which uses some code from Ron De Bruin and assumes you use Outlook as your email client). The file includes a macro so (on opening) you'll need to enable macros before it will work.
You'll see a green button "Send 999 emails" (for now somewhat inconveniently placed near top left of the Report sheet- it can be moved). Click that and the current version should create but not send (though you can) a single email related to the third line of your Report sheet. Check it does what you expect, albeit the product stock data is after the email body (from cell AC3).
If that works well for you, it can be extended to produce emails for all 999 cells from a single click.
Please do as follows to send an email based on cell value in Excel.
1. In the worksheet you need to send an email based on its cell value, right-click the sheet tab, and select View Code from the context menu.
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
Hope this was helpful.