I tried searching for this but I am new to vba and the terminology. I've cobbled up the coding from other peoples codes to create mine. Everything was working fine until i decided to get cute and add a body to the email.
Heres what I am trying to do...
If column F is > 7, an email is to be sent to the supervisor stating so. I was the body of the email to contain info from a few other cells in the same row as the cell that triggered the email. You will probably look at the coding and laugh at me cuz it is probably something easy...I'm sure you will see what I am trying to do just by looking at it. Also, while we are at it, vbNewLine doesn't seem to work in the email body...what's up with that?
Here is my code and thanks a ton in advance!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngResponse As Long
Dim URL As String, strEmail As String, strSubject As String, strTank As String, strVolume As String, strInlet As String, strOutlet As String
If Left(Target.Address, 2) = "$F" Then
strTank = "$C"
strVolume = "$D"
strInlet = "E"
strOutlet = "F"
If Target.Value > 7 And Target.Text <> "" Then
lngResponse = MsgBox("The hardness of the softeners outlet is too high. Hardness should not be greater than 7, your supervisor must be notified." & vbNewLine & vbNewLine & "Note: Clicking OK will open Outlook and create the email message. You must click send once the email is open.", vbOKOnly)
If lngResponse = vbOK Then
Shell ("OUTLOOK")
strEmail = "Brian.Kuhn@EqOnline.com"
strSubject = "Softener outlet hardness is greater than 7"
strSubject = Application.WorksheetFunction.Substitute(strSubject, " ", "%20")
strBody = "Tank = " & strTank & vbNewLine & "Volume Remaining = " & strVolume & vbNewLine & "Inlet Hardness = " & strInlet & vbNewLine & "Outlet Hardness = " & strOutlet
strBody = Application.WorksheetFunction.Substitute(strBody, " ", "%20")
strURL = "mailto:" & strEmail & "?subject=" & strSubject & "&body=" & strBody
ShellExecute 0&, vbNullString, strURL, vbNullString, vbNullString, vbNormalFocus
End If
End If
End If
End Sub
Bookmarks