Mail Merge Tool Help - Subject Line/ Main Text Question

S_W_Langdon

New Member
Joined
Feb 5, 2018
Messages
13
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.

Code:
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


                .Send
            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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,303
Messages
5,836,520
Members
430,437
Latest member
Emilycr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top