raccoon588
Board Regular
- Joined
- Aug 5, 2016
- Messages
- 118
I am trying to get the code to send out emails based on a cell meeting a specific requirement. half way through i redo the code with a different email but i get an error once it reaches this second round. the warning is saying something isn't declared but i can not figure it out. the first email sends fine.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("K6:k8800"), Target) Is Nothing Then ActiveWorkbook.Save
If Not Intersect(Target, Range("K:K")) Is Nothing Then
If Range("x7") = 15 Then
MsgBox "Click OK once you have notified your supervisor.(3hrs Supervisor)", vbOKOnly + vbExclamation, "Low Production Warning"
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "ex@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Update
End With
strbody = "WARNING" & vbNewLine & vbNewLine & _
"Production line has been below" & vbNewLine & _
"goal for 3 or MORE hours." & vbNewLine & _
"" & vbNewLine & _
""
With iMsg
Set .Configuration = iConf
.To = "me@osram.com"
.CC = ""
.BCC = ""
' Note: The reply address is not working if you use this Gmail example
' It will use your Gmail address automatic. But you can add this line
' to change the reply address .ReplyTo = "Reply@something.nl"
.From = "lowproductionwarning@gmail.com"
.Subject = "S8W A9"
.TextBody = strbody
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
If Range("x8") = 20 Then
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "me@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Update
End With
strbody = "WARNING" & vbNewLine & vbNewLine & _
"Production line has been below" & vbNewLine & _
"goal for 4 or MORE hours." & vbNewLine & _
"" & vbNewLine & _
""
With iMsg
.To = "me@osram.com"
.CC = ""
.BCC = ""
' Note: The reply address is not working if you use this Gmail example
' It will use your Gmail address automatic. But you can add this line
' to change the reply address .ReplyTo = "Reply@something.nl"
.From = "lowproductionwarning@gmail.com"
.Subject = "S8W A9"
.TextBody = strbody
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End If
End If
End If
End Sub