Not in SendMail procedure just paste this line in worksheet_change event procedure from where you calling sendmail procedure
Regards, Lalit Mohan On Friday, 31 August 2012 18:02:02 UTC+2, selva wrote: > > Hi All, > > > > Need an update on the attached macro file. Based on this file, whenever > the Column N drop down is selected for ‘Failure’, an outlook mail > generates and ready to be sent. If ‘Success’ is selected no mails will be > sent. But my issue is whenever I select for ‘Failure’ in Column O. Two > mails are being generated for Column N and for Column O. But I want to > restrict it to one mail for that cell which I have selected only. Can any > one help me on this? > > > > Code:- > > > > Sub sendEmail() > > > > Dim objOL As Object > > Dim objMail As Object > > Dim sEmail As String > > Dim sEmailColumn As String > > Dim sSubject As String > > Dim sBody As String > > Dim lDataRow As Long > > Dim cl As Range > > 'Set column with email address > > sEmailColumn = "Z" > > For Each cl In Selection.Resize(, 1) > > > > lDataRow = cl.Row > > > > If cl.Parent.Range("N" & lDataRow).Value = "Failure" Then > > With cl.Parent > > sEmail = .Range(sEmailColumn & lDataRow) > > sSubject = Range("B" & lDataRow) > > sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & > vbNewLine & "Step A" > > End With > > > > On Error GoTo Cleanup > > > > Set objOL = CreateObject("Outlook.Application") > > > > Set objMail = objOL.CreateItem(0) > > With objMail > > .To = sEmail > > .Subject = sSubject > > .Body = sBody > > .Display > > End With > > End If > > Next cl > > For Each cl In Selection.Resize(, 1) > > > > lDataRow = cl.Row > > > > If cl.Parent.Range("O" & lDataRow).Value = "Failure" Then > > With cl.Parent > > sEmail = .Range(sEmailColumn & lDataRow) > > sSubject = Range("B" & lDataRow) > > sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & > vbNewLine & "STEP B" & vbNewLine & "<Insert Screenshots here>" > > End With > > > > On Error GoTo Cleanup > > > > Set objOL = CreateObject("Outlook.Application") > > > > Set objMail = objOL.CreateItem(0) > > With objMail > > .To = sEmail > > .Subject = sSubject > > .Body = sBody > > .Display > > End With > > End If > > Next cl > > For Each cl In Selection.Resize(, 1) > > > > lDataRow = cl.Row > > > > If cl.Parent.Range("P" & lDataRow).Value = "Failure" Then > > With cl.Parent > > sEmail = .Range(sEmailColumn & lDataRow) > > sSubject = Range("B" & lDataRow) > > sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & > vbNewLine & "STEP C" & vbNewLine & "<Insert Screenshots here>" > > End With > > > > On Error GoTo Cleanup > > > > Set objOL = CreateObject("Outlook.Application") > > > > Set objMail = objOL.CreateItem(0) > > With objMail > > .To = sEmail > > .Subject = sSubject > > .Body = sBody > > .Display > > End With > > End If > > Next cl > > For Each cl In Selection.Resize(, 1) > > > > lDataRow = cl.Row > > > > If cl.Parent.Range("Q" & lDataRow).Value = "Failure" Then > > With cl.Parent > > sEmail = .Range(sEmailColumn & lDataRow) > > sSubject = Range("B" & lDataRow) > > sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & > vbNewLine & "STEP D" & vbNewLine & "<Insert Screenshots here>" > > End With > > > > On Error GoTo Cleanup > > > > Set objOL = CreateObject("Outlook.Application") > > > > Set objMail = objOL.CreateItem(0) > > With objMail > > .To = sEmail > > .Subject = sSubject > > .Body = sBody > > .Display > > End With > > End If > > Next cl > > > > Regards,** > > Selva Jayapal** > > Accenture - IDC, Chennai > > PMO - Operations > > Desk - +91 44 426 70619 > > Mobile - +91 7708658033 > > Office Communicator : selva.jaya...@accenture.com <javascript:> > -- Join official facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES (1120+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. 6) Jobs posting is not allowed. 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To post to this group, send email to excel-macros@googlegroups.com. To unsubscribe from this group, send email to excel-macros+unsubscr...@googlegroups.com.