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