swilliams658
New Member
- Joined
- Nov 6, 2014
- Messages
- 3
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD] Name[/TD]
[TD]Primary Email[/TD]
[TD]CC[/TD]
[TD]File 1[/TD]
[TD]File 2[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]emailohn[/TD]
[TD][/TD]
[TD]pathway[/TD]
[TD]pathway2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jane[/TD]
[TD]emailjane[/TD]
[TD]email1;email2[/TD]
[TD]pathway[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Hello,
I am trying to create a macro that will send individual emails (with specific CC's associated) PDF files, sometimes multiple files. I obviously need it to run with no CCs or if there are 1 or 4 files. I have found a code, but I'm not exactly sure I know how to populate it. Any help would be appreciated!
Thanks!
Suzy
Sub Send_Files()
'Working in Excel 2000-2013
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
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("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("B1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = ThisWorkbook.Sheets("Sheet2").Range("E2").Value
.to = cell.Value
.CC = ""
.BCC = ""
.Subject = ThisWorkbook.Sheets("Sheet2").Range("E6").Value
.Body = ThisWorkbook.Sheets("Sheet2").Range("B8").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
.display 'Or use Send
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD] Name[/TD]
[TD]Primary Email[/TD]
[TD]CC[/TD]
[TD]File 1[/TD]
[TD]File 2[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]emailohn[/TD]
[TD][/TD]
[TD]pathway[/TD]
[TD]pathway2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jane[/TD]
[TD]emailjane[/TD]
[TD]email1;email2[/TD]
[TD]pathway[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Hello,
I am trying to create a macro that will send individual emails (with specific CC's associated) PDF files, sometimes multiple files. I obviously need it to run with no CCs or if there are 1 or 4 files. I have found a code, but I'm not exactly sure I know how to populate it. Any help would be appreciated!
Thanks!
Suzy
Sub Send_Files()
'Working in Excel 2000-2013
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
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("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("B1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = ThisWorkbook.Sheets("Sheet2").Range("E2").Value
.to = cell.Value
.CC = ""
.BCC = ""
.Subject = ThisWorkbook.Sheets("Sheet2").Range("E6").Value
.Body = ThisWorkbook.Sheets("Sheet2").Range("B8").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
.display 'Or use Send
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub