Save worksheets as separate PDFs and then e-mail them to separate recipients

bjacobs

New Member
Joined
May 1, 2018
Messages
1
Hello gurus,

I am new to the forum and new to forums in general (I know, what rock did I crawl out from?)

Anyway, I'm not too strong in VBA, but I'm decent with Excel.

I have a workbook with multiple worksheets in it. Each worksheet is a person's name, and each worksheet has sensitive data for only that person. One of the cells in each worksheet is the person's e-mail address (cell B37).

Every 2 weeks, I paste a large batch of data onto a separate sheet in the WB and the WS's automatically calculate all of the data.

I need to create a macro to automatically save each worksheet as a separate PDF (worksheet name as the .PDF is fine) and then automatically send each of those PDFs to the recipients as listed in each of the worksheet's e-mail address cell.

I've searched Google and this forum, and I built some of the pieces gradually. So far, my code saves all of the .PDF files, but I can't figure out how to connect the Outlook portion properly.

I appreciate any help in advance, and I hope that I have followed all of the forum rules.

I am aware that the portion "myattachments.Add ActiveWorkbook.Path & "" &" is incomplete. I doubt it's even proper here, but I was stumped, so here I am.

My code is below:

Code:
Sub sendReminderMail()
ChDir "C:\Users\jacobsb\Desktop\2018 DC Dashboards"


Dim strPath As String
Dim wks As Worksheet


strPath = ActiveWorkbook.Path & "\"


For Each wks In ActiveWorkbook.Worksheets
    wks.ExportAsFixedFormat xlTypePDF, strPath & wks.Name & ".pdf"
Next wks


Dim Outlookapp As Object
Dim Outlookmailitem As Object
Dim myattchments As Object


Set Outlookapp = CreateObject("Outlook.application")
Set Outlookmailitem = Outlookapp.createitem(0)
Set myattachments = Outlookmailitem.attachments


With Outlookmailitem
.To = [b37]
.Subject = "Distribution Doc"
.Body = "Attached is the Doc"
myattachments.Add ActiveWorkbook.Path & "\" &
'.send
.Display
End With


Set Outlookmailitem = Nothing
Set Outlookapp = Nothing


End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top