Results 1 to 6 of 6

Send different file to each person in a range

Threaded View

  1. #1
    Registered User
    Join Date
    02-28-2012
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    37

    Send different file to each person in a range

    Hi guys,

    I am having a small problem with one of Ron de Bruin's macros. I hope one of you can help me with it.

    In the workbook attached, I have the names in column A, e-mails addresses in column B, an auxiliary file in column C and the file to be attached in column D.

    I would like to have two different macros: one that would send the e-mails in rows 2-7 and the other to send the e-mails in rows 10-18, always attaching only the file in column D.

    How can I modify the following code to make it work?

    Thanks in advance!!!

    Sub Prepara_Emails()
    
        Dim OutApp As Object
        Dim OutMail As Object
        Dim sh As Worksheet
        Dim cell As Range, FileCell As Range, rng As Range
    
        With Application
            .DisplayAlerts = False
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
    NOME = "E-mail Subject"
    
    Set sh = Sheets("Macros")
    
        Set OutApp = CreateObject("Outlook.Application")
    
        For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
    
            Set rng = sh.Cells(cell.Row, 1).Range("D1:D1")
    
            If cell.Value Like "?*@?*.?*" And _
               Application.WorksheetFunction.CountA(rng) > 0 Then
                Set OutMail = OutApp.CreateItem(0)
    
                With OutMail
                    .To = cell.Value
                    .cc = "Me"
                    .Subject = NOME
                    .HTMLBody = "<html><body> Hi</body></html>"
                    
                    For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                        If Trim(FileCell) <> "" Then
                            If Dir(FileCell.Value) <> "" Then
                                .Attachments.Add FileCell.Value
                            End If
                        End If
                    Next FileCell
                    
                    .Display
                End With
    
                Set OutMail = Nothing
            End If
        Next cell
    
        Set OutApp = Nothing
    
        With Application
            .DisplayAlerts = True
            .EnableEvents = True
            .ScreenUpdating = True
        End With
        
    End Sub
    Example2.xlsx
    Last edited by pedrofogao21; 03-30-2012 at 08:42 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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