+ Reply to Thread
Results 1 to 2 of 2

I have created a VBA code to send mails in Excel.

  1. #1
    Registered User
    Join Date
    12-07-2019
    Location
    maldives
    MS-Off Ver
    office suite 2010
    Posts
    2

    Post I have created a VBA code to send mails in Excel.

    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

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: I have created a VBA code to send mails in Excel.

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Send e-mails from Excel Issue
    By Chivers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2018, 11:03 AM
  2. Replies: 1
    Last Post: 01-26-2016, 01:05 PM
  3. Unable to Send mails using cell range with proper formatting as per code
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2015, 12:27 PM
  4. [SOLVED] Macro to send mails from outlook as per the email ids in excel
    By arun.sj in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-03-2015, 12:10 PM
  5. Send custom E-mails from Excel
    By lord_enzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2012, 06:02 AM
  6. [SOLVED] Send multiple e-mails from Excel using VBA
    By JFreeland in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2012, 08:20 AM
  7. Having excel send e-mails automatically
    By gcol in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2007, 09:28 AM

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