Below is the code i have created to send mails through excel . My problem is below for below code i have select each row and then can send mail .
Could some one help me when i sent email button , all mail can go in one time which in my excel cells mention "send reminder".
so is there any way to use it for only the active sheet or work book
Sub btnSendEmail()
Dim objSession As Object
Dim strMailDBName As String
Dim objMailDB As Object
Dim objMailDoc As Object
Dim strSignature As String
Dim varRecipientTo As Variant
Dim varRecipientCC As Variant
Dim strSubject As String
Dim Introw As Integer
Introw = ActiveCell.Row
If ActiveSheet.Range("K" & Introw) <> "" And InStr(1, Trim(ActiveSheet.Range("J" & Introw)), "send reminder", vbTextCompare) <> 0 Then
Set objSession = CreateObject("Lotus.NotesSession")
objSession.Initialize ("MNResmgr") 'énter your Lotus Notes password here
strMailDBName = "mail\mnresmgr.nsf"
Set objMailDB = objSession.GetDatabase("MVDNMN01", strMailDBName)
If Not objMailDB.IsOpen Then Call objMailDB.Open
' Create New Mail and Address Title Handlers
Set objMailDoc = objMailDB.CreateDocument
strSignature = objMailDB.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
' Select range of e-mail addresses
If InStr(1, ActiveSheet.Range("K" & Introw).Value, ";", vbTextCompare) = 0 Then
varRecipientTo = ActiveSheet.Range("K" & Introw).Value
Else
varRecipientTo = Split(ActiveSheet.Range("K" & Introw).Value, ";")
End If
If InStr(1, ActiveSheet.Range("L" & Introw).Value, ";", vbTextCompare) = 0 Then
varRecipientCC = ActiveSheet.Range("L" & Introw).Value
Else
varRecipientCC = Split(ActiveSheet.Range("L" & Introw).Value, ";")
End If
strSubject = ""
If ActiveSheet.Range("M" & Introw).Value <> "" Then strSubject = ActiveSheet.Range("M" & Introw).Value
If ActiveSheet.Range("F" & Introw).Value <> "" Then
If strSubject = "" Then strSubject = ActiveSheet.Range("F" & Introw).Value Else strSubject = strSubject & " - " & ActiveSheet.Range("F" & Introw).Value
End If
Call objMailDoc.ReplaceItemValue("Form", "Memo")
Call objMailDoc.ReplaceItemValue("SendTo", varRecipientTo)
Call objMailDoc.ReplaceItemValue("CopyTo", varRecipientCC)
Call objMailDoc.ReplaceItemValue("Subject", strSubject)
Dim objMailBody As Object
Set objMailBody = objMailDoc.CreateRichTextItem("Body")
Call objMailBody.AddNewLine(2)
Call objMailBody.AppendText(ActiveSheet.Range("N" & Introw).Value & vbCrLf & vbCrLf & strtSignature)
objMailDoc.SaveMessageOnSend = True
Call objMailDoc.ReplaceItemValue("PostedDate", Now())
On Error GoTo Err_Handler
Call objMailDoc.Send(False)
MsgBox "The email has been sent.", vbOKOnly + vbExclamation, "Ëmail Sent"
End If
Err_Handler:
If Err.Description <> "" Then MsgBox Err.Number & " - " & Err.Description
Set objMailDB = Nothing
Set objMailDoc = Nothing
Set objSession = Nothing
End Sub
Bookmarks