+ Reply to Thread
Results 1 to 9 of 9

Help converting single recipient email macro to limitless

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Help converting single recipient email macro to limitless

    I want to be able to add multiple email addresses and have the macro send a separate email for them all. Don't ask why not a single with multiple recipients, I do not know, I am helping someone else out.

    How much more difficult would it to instead reference another workbook, "Addresses" and so if the email addresses need to be adjusted that workbook can be opened instead of the macro?

    Sub EmailCPR()
       
       ' Select the range of cells on the active worksheet.
       ActiveSheet.Range("X1", ActiveSheet.Range("A1").End(xlDown)).Select
       
       ' Show the envelope on the ActiveWorkbook.
       ActiveWorkbook.EnvelopeVisible = True
       
       ' Set the optional introduction field thats adds
       ' some header text to the email body. It also sets
       ' the To and Subject lines. Finally the message
       ' is sent.
       With ActiveSheet.MailEnvelope
          .Introduction = "Production Report."
          .Item.To = "[email protected]"
          .Item.Subject = Format(Now, "mm-dd-yy ") & "Production Report"
       End With
    End Sub

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,350

    Re: Help converting single recipient email macro to limitless

    Hi taylorsm

    Perhaps a loop referencing an range of cells with the email addresses...something like this:
    Dim LastRow As Long
    Dim i As Long
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow 'First email address starts in A2
        'Not to sure what email service you are using
        With ActiveSheet.MailEnvelope
            .Introduction = "Production Report."
            .Item.To = ActiveSheet.Range("A" & i).Value
            .Item.Subject = Format(Now, "mm-dd-yy ") & "Production Report"
        End With
    Next i
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Help converting single recipient email macro to limitless

    My apologizes. it would be microsoft outlook 2016.

    I found out more about the process later yesterday, person I am helping will download an excel file from our software and then use the addresses that are in that file to send the emails to. Is it possible to have a location box pop up asking for the file in order to pull the addresses? So they would download a file, then in this spreadsheet they would run the macro, select the download location of that other file and it would pull those emails? If that is far more complicated then that is ok, they can open the downloaded file and copy/paste into their own.



    And just in case anyone is concerned, this is not spam! lol. This is in direct and immediate response to a request.

  4. #4
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Help converting single recipient email macro to limitless

    Idk if I can one "bump" a thread or not..

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,350

    Re: Help converting single recipient email macro to limitless

    Let try this method: Code prompts user to select the file to open, then assuming that email addresses are stored in Column A, loops and sends email to each address found in col A...This is for Outlook 2007
    Option Explicit
    Sub SendEmail()
    Dim EmailSubject As String
    Dim Email_To As String, Email_CC As String, Email_BCC As String, Email_Body As String
    Dim DisplayEmail As Boolean
    Dim OutlookApp As Object, OutlookMail As Object
    Application.ScreenUpdating = False
    Dim LastRow As Long
    Dim i As Integer
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim fNameAndPath As Variant
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    Set wb = Workbooks.Open(fNameAndPath)
    LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LastRow 'First email address starts in A1
        EmailSubject = "This is a test"
        DisplayEmail = True
        Email_To = StrConv(ActiveSheet.Range("A" & i), vbLowerCase)
        Email_Body = "Good afternoon"
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookMail = OutlookApp.CreateItem(0)
        With OutlookMail
            .Display
            .To = Email_To
            .CC = Email_CC
            .BCC = Email_BCC
            .Subject = EmailSubject
            '.HTMLBody = Sp & Email_Body & .HTMLBody
            '.Attachments.Add PDFFile
            If DisplayEmail = False Then
            .Send
            End If
        End With
    Next i
    Application.ScreenUpdating = True
    wb.Close savechanges:=True 'or false
    End Sub

  6. #6
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Help converting single recipient email macro to limitless

    Thanks sintek! Since we are using 2016, would that change anything?

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,350

    Re: Help converting single recipient email macro to limitless

    Not to sure taylorsm...Can only test to find out.

  8. #8
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Help converting single recipient email macro to limitless

    So I opened a spreadsheet and ran the macro and the only thing it emailed was a blank email with "this is a test" in the subject, nothing in the body other than my signature.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,350

    Re: Help converting single recipient email macro to limitless

    Yep that's right...Was just a test.You will have to edit to add your Subject, body etc.
    Option Explicit
    Sub Auto_Open()
    Dim EmailSubject As String
    Dim Email_To As String, Email_CC As String, Email_BCC As String, Email_Body As String
    Dim DisplayEmail As Boolean
    Dim OutlookApp As Object, OutlookMail As Object
    Application.ScreenUpdating = False
    Dim LastRow As Long
    Dim i As Integer
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim fNameAndPath As Variant
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
    If fNameAndPath = False Then Exit Sub
    Set wb = Workbooks.Open(fNameAndPath)
    LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LastRow 'First email address starts in A1
        EmailSubject = "This is the information pertaining to your subject" ' Or it can be a reference to a Range
        DisplayEmail = True
        Email_To = StrConv(ActiveSheet.Range("A" & i), vbLowerCase)
        Email_Body = "This is where you put in your information pertaining to your email body"
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookMail = OutlookApp.CreateItem(0)
        With OutlookMail
            .Display
            .To = Email_To
            .CC = Email_CC
            .BCC = Email_BCC
            .Subject = EmailSubject
            .HTMLBody = Sp & Email_Body & .HTMLBody
            '.Attachments.Add PDFFile' Here you can add any attachments ...Just remove the "'" Character
            If DisplayEmail = False Then
            .Send
            End If
        End With
    Next i
    Application.ScreenUpdating = True
    wb.Close savechanges:=True 'or false
    End Sub

+ 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. Emailing sheet to a recipient in cell A1; using Ron DeBriuns's email macro
    By bhola-bhala in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2014, 07:06 PM
  2. Figuring out how to send Excel single sheet to a non predefined email recipient
    By bhola-bhala in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2014, 12:46 PM
  3. Macro to create folders for each email recipient
    By neodjandre in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2013, 05:38 AM
  4. Macro to email range of data for each recipient from multiple worksheets
    By Ram84 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-13-2013, 04:03 PM
  5. Macro that will send a separate email to each recipient in range
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2013, 02:17 PM
  6. Macro to extract worksheet to email recipient
    By weesteev in forum Excel General
    Replies: 1
    Last Post: 12-21-2011, 09:04 AM
  7. macro: check recipient email, warn if sending through wrong account
    By as_sass in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2010, 04:26 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