Option Explicit
Sub PC_Email()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim MailAttachments As String
Dim cell As Variant ' Not previously DIM'd
Sheets("Sheet1").Select ' Edit as required
Range("A1").Select
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
If WorksheetFunction.CountA(Range("K2:K100")) = 0 Then
MsgBox "To send email, please enter an X in Column K.", vbCritical, "Missing Entry"
Exit Sub
End If
For Each cell In Columns("C").Cells
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "K").Value) <> "" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
strbody = "Please Delete Any Previous Emails Related To This Period" & vbNewLine & vbNewLine & _
"Good Morning, " & vbNewLine & vbNewLine & _
"Please find attached applicable for WC: " & Cells(cell.Row, "A") & vbNewLine & vbNewLine & _
" " & Cells(cell.Row, "F") & " " & Cells(cell.Row, "G") & vbNewLine & vbNewLine & _
"KR" & vbNewLine & vbNewLine & _
"Trevor M" & vbNewLine & vbNewLine & _
"Ext" & vbNewLine & vbNewLine & _
"2663"
.To = Cells(cell.Row, "C").Value
.cc = Cells(cell.Row, "D").Value
.bcc = Cells(cell.Row, "E").Value
.Subject = "Trevor McLaughlin - Timesheet & Expenses Claim For WC " & Cells(cell.Row, "A").Value
.Body = strbody
'.Attachments.Add Application.ActiveWorkbook.FullName
.Attachments.Add ActiveSheet.Cells(cell.Row, "H").Value
.Attachments.Add ActiveSheet.Cells(cell.Row, "I").Value
.Attachments.Add ActiveSheet.Cells(cell.Row, "J").Value
.display 'Or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Sub ClrMailToSend()
Sheets("Sheet1").Range("K2:K100").Value = ""
End Sub
Sub GetFilePath()
Dim dialogBox As FileDialog
Set dialogBox = Application.FileDialog(msoFileDialogOpen)
'Set the display properties - these are optional
'All the settings must be applied before the .Show command
'Do not allow multiple files to be selected
dialogBox.AllowMultiSelect = False
'Set the title of of the DialogBox
dialogBox.Title = "Select a file"
'Set the initial path to :
dialogBox.InitialFileName = "C:\data"
'Show the dialog box and output full file path and file name
If dialogBox.Show = -1 Then
ActiveCell.Value = dialogBox.SelectedItems(1)
End If
End Sub