+ Reply to Thread
Results 1 to 12 of 12

send email to multiple recipients

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    596

    Re: send email to multiple recipients

    Here is what I "hammered" together (spread sheet attached); Does not look very good but works until I am listing more than one recipient in one cell:
    '---------------------------------------------------------------------------------------------------------------------------------------------------
    Public olApp As New Outlook.Application
    Public nsMAPI As Outlook.Namespace
    Public exp As Outlook.Explorer

    '=========================Function CountFiles================================================================
    Function CountFiles(tgtDir As String) As Integer
    Dim fName As String
    'Retrieve the first entry, handle error if directory not found
    On Error GoTo badDirectory
    fName = Dir(tgtDir & "\*.*")

    On Error GoTo 0

    'loop through all files in the directory and increment the function's value
    Do While fName <> ""

    ' Ignore the current directory and
    ' the encompassing directory.

    If fName <> "." And fName <> ".." Then
    CountFiles = CountFiles + 1
    End If

    ' Get next entry.
    fName = Dir()
    Loop
    Exit Function

    badDirectory:
    'come here if directory cannot be accessed
    MsgBox "The directory you specified does not exist or " & _
    "cannot be accessed. Activity halted."
    End



    End Function

    '=========================END FUNCTION COUNTFILES============================================================

    Sub EmailRFQ()
    Dim itmMail As Outlook.MailItem
    Dim x As Variant
    Dim y As Variant
    Dim k As Integer
    Dim RecipientName As String
    Dim Manuf As String
    Dim RecipientEmail As String
    Dim myAttachments As Outlook.Attachments
    Dim filecount As Integer
    Dim strFolder As String
    Dim strFileN As String
    Dim mymessage As String
    k = 0
    filecount = 0
    Filelocation = Application.ActiveWorkbook.Path
    strFolder = Filelocation & "\Attachments\"
    filecount = CountFiles(Filelocation & "\Attachments\")


    'Return a reference to the MAPI layer
    Set nsMAPI = olApp.GetNamespace("MAPI")

    'Set the current cell selection equal to the e-mail address
    'x = ActiveCell.Value
    x = ActiveSheet.Range(Cells(1, 2), Cells(1, 2))
    If x = "" Then
    CreateObject("WScript.Shell").Popup "Message Is Empty ", 2
    Exit Sub
    End If
    Do
    'x = Range("b2").Value


    RecipientName = Range(Cells(2 + k, 1), Cells(2 + k, 1))


    RecipientEmail = Range(Cells(2 + k, 2), Cells(2 + k, 2))


    Manuf = Range(Cells(2 + k, 3), Cells(2 + k, 3))
    If x = "" Then Exit Do

    If RecipientEmail = "" Then Exit Do


    'Set the cell RecipientsSheet!b1 equal to the message body
    Application.ScreenUpdating = False
    Worksheets("RecipientsSheet").Activate
    y = Range("b1").Value

    'Create a New mail message item
    Set itmMail = olApp.CreateItem(olMailItem)
    Set myAttachments = itmMail.Attachments
    With itmMail

    'Add the subject of the mail message
    .Subject = Range("a1").Value
    'Create some body text
    .Body = RecipientName & "," & vbNewLine & vbNewLine & _
    y & vbCrLf & vbNewLine & vbNewLine & _
    "Please respond to confirm ..." & vbNewLine & vbNewLine & _
    "Thank you," & vbNewLine & vbNewLine & _
    "My Name" & vbNewLine & _
    "My Title"

    'Add a recipient and test to make sure that the
    'address is valid using the Resolve method

    With .Recipients.Add(RecipientEmail)

    .Type = olTo
    If Not .Resolve Then
    MsgBox "Unable to resolve address."
    Exit Sub
    End If
    End With

    '============add Attachment==================================================


    strFileN = Dir(strFolder & FileType)

    Do While Len(strFileN) > 0
    myAttachments.Add strFolder & strFileN
    strFileN = Dir
    Loop

    'itmMail.Display
    '======================END add Attachment



    .Send
    End With


    'Release memory
    Set itmMail = Nothing
    Set nsMAPI = Nothing
    Set olApp = Nothing
    k = k + 1
    Loop
    ExitProc:
    Set olApp = Nothing
    CreateObject("WScript.Shell").Popup "RFQ-s Sent to " & k & " Recipients", 3



    1000 End Sub
    Attached Files Attached Files

+ 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. Send workbook via email to multiple recipients
    By jdavies294 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-16-2014, 10:44 AM
  2. [SOLVED] How to send Lotus email with VBA to more recipients and also to more copy recipients
    By Sachy in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-20-2013, 03:23 PM
  3. send email from excel to multiple recipients
    By hariexcel1987 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 01-13-2013, 01:41 PM
  4. Send email to multiple recipients
    By Court16 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2009, 05:20 PM
  5. Send workbook via email to multiple recipients
    By lethal in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-25-2008, 06:58 PM

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