Mail Merge Tool Help - Subject Line/ Main Text Question


New Member
Feb 5, 2018
Hi Everyone,

I am hoping someone will be able to help me out on the below, as I am stumped and only so long I can stair at my screen with a blank expression as I pour through google/ forums with no luck :LOL:

So as the title suggests I am setting up a mail merge tool, and I have got it working but would like to expand on what I currently have, but unsure if it is possible or not.

Currently the tool looks in a folder and adds all PDF's within to a column within Excel, this then uses some formula to get the email address and other information that will be needed to send these documents out to the recipients, and then looks at another tab for the Subject Line and Text to be added to the email (This all works fine)

What I would like to do if possible, is have the Subject line (preferably) different for each mail sent out, rather than a static one that is typed in, so it would look at something unique for each email say the Reference Number and add this into the Subject Line.
(although the main body of text is also an option, but if the subject line is possible I would assume it would be the same coding)

Here is the coding that I have so far (Highlighted the Subject Line Code in Bold Red)
As I said I don't know if this is possible or not, but would like to know one way or the other so I can stop going crazy trying to figure this out.

Sub Send_Files()    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim cell As Range
    Dim FileCell As Range
    Dim rng As Range

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set sh = Sheets("Distribution")

    Set OutApp = CreateObject("Outlook.Application")

    For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)

               Set rng = sh.Cells(cell.Row, 1).Range("C1:d1")

        If cell.Value Like "?*@?*.?*" And _
           Application.WorksheetFunction.CountA(rng) > 0 Then
            Set OutMail = OutApp.CreateItem(0)

            With OutMail
                .to = cell.Value
                [COLOR=#ff0000][B].Subject = Sheets("E-Mail Text").Range("B3").Value[/B][/COLOR]
                .Body = Sheets("E-Mail Text").Range("B6").Value

                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

            End With

            Set OutMail = Nothing
        End If
    Next cell

    Set OutApp = Nothing
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
        'Message box
   MsgBox "Finished"
End Sub

Thanks Everyone

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...