I made some small changes to the first macro I had made, so you will need to replace the code in that module with the code below:
Sub jw01pdf()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lr As Long, i As Long
Dim myPath As String
Dim myFileName As String
Set ws2 = Worksheets("Summary")
Set ws1 = Worksheets("Employees")
lr = ws1.Range("A" & Rows.Count).End(xlUp).Row
myPath = "C:\Users\TORHXH\Desktop\Timekeeper performance overview\PDF\May\"
For i = 2 To lr
ws2.Range("E7").Value = ws1.Range("A" & i).Value
Worksheets(Array("Summary", "WIP Table", "AR Table")).Select
myFileName = myPath & ws1.Range("A" & i).Value & " - " & MonthName(Month(Date))
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFileName, quality:=xlQualityStandard _
, includedocproperties:=True, ignoreprintareas:=False, openafterpublish:=True 'change openafterpublish to false if you don't want the pdf to open
ws1.Activate 'this line just selects the first sheet to un-select the group of 3... keeping those selected was causing other code to write to "Summary" when it should be writing to other sheets.
Call jw01mailer(myFileName & ".pdf", ws1.Range("B" & i).Value, ws1.Range("A" & i).Value, Date)
Next i
End Sub
Function jw01mailer(myFile As String, toMail As String, recipient As String, myDate As Date)
Dim Oapp As Object
Dim Omail As Object
Dim myMsg As String
'string below is the body of the email, using html tags for formatting, so each <br> is a line break
myMsg = "<p style=""font-size:11pt"">Hello " & recipient & "," & "<br><br>" & "Attached is you performance dashboard that shows you Key " _
& "Performance Indicators (KPIs) as at FY " & Format(myDate, "mmmm, yyyy") & ", which shows the following KPIs:" & "<br>" & _
"1. ABC" & "<br>" & " 2. ABC" & "<br>" & "3. ABC" & "<br>" & "4. ABC" & "<br><br>" & _
"The purpose of this dashboard is to keep you apprised of your own progress so that you can plan accordingly for the remainder of the year." & _
"<br><br>" & "If you have any questions or feedback related to your report of the KPIs, please do not hesitate to reach out to me.</p>"
Set Oapp = CreateObject("Outlook.Application")
Set Omail = Oapp.createitem(0)
With Omail
.display 'code works without this, but if you take it out outlook won't have the signature in the email
.to = toMail
.Subject = recipient & " TK Performance overview – " & Format(myDate, "mmmm, yyyy")
.htmlbody = myMsg & .htmlbody
.attachments.Add myFile
'.send 'enable this line once you are satisfied the email is building properly
End With
Set Omail = Nothing
Set Oapp = Nothing
End Function
Bookmarks