S_W_Langdon
New Member
- Joined
- Feb 5, 2018
- Messages
- 13
Hello Everyone,
I am hoping someone can help,
I have setup some VBA to send out Documents via a list of people and addresses within my Excel List, this works fine for most areas, but I have one area that needs a custom Body of text per email and I am unsure on how to do this.
Here is my code so far, as you can see the the To: goes to every email within my list but the Subject/ Body are static based on cells.
My initial thought is to pull information from Word Documents that are currently being used by this team to generate the email text, but I don't know where to start.
My second idea was to still use static fields, but to add in some fomula/ VBA that change parts of the text based on a loop within the VBA using the Email as a lookup value, but again this is beyond my current knowledge.
Any help would be great thanks everyone
I am hoping someone can help,
I have setup some VBA to send out Documents via a list of people and addresses within my Excel List, this works fine for most areas, but I have one area that needs a custom Body of text per email and I am unsure on how to do this.
Here is my code so far, as you can see the the To: goes to every email within my list but the Subject/ Body are static based on cells.
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
[COLOR=#008000][B] .To = cell.Value[/B][/COLOR]
[COLOR=#008000][B] .Subject = Sheets("E-Mail Text").Range("B3").Value[/B][/COLOR]
[COLOR=#008000][B] .Body = Sheets("E-Mail Text").Range("B6 & B6").Value[/B][/COLOR]
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
My initial thought is to pull information from Word Documents that are currently being used by this team to generate the email text, but I don't know where to start.
My second idea was to still use static fields, but to add in some fomula/ VBA that change parts of the text based on a loop within the VBA using the Email as a lookup value, but again this is beyond my current knowledge.
Any help would be great thanks everyone