+ Reply to Thread
Results 1 to 2 of 2

Email body contains cells from row with cell that triggers the email

Hybrid View

aaronp Email body contains cells... 05-01-2013, 08:30 PM
aaronp Re: Email body contains cells... 05-03-2013, 08:56 PM
  1. #1
    Registered User
    Join Date
    11-01-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Email body contains cells from row with cell that triggers the email

    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

  2. #2
    Registered User
    Join Date
    11-01-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Email body contains cells from row with cell that triggers the email

    no takers?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1