Hi Travis,
To add the step of printing to a PDF before sending the email, you can use the
"ExportAsFixedFormat" method in VBA. Here are the steps to do this:
- Open the VBA editor by pressing Alt + F11.
- Double-click on the button that you have created to open the code window.
- Add the following code to print the active sheet to a PDF file:
Formula:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\YourUserName\Documents\FileName.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Replace "YourUserName" with your actual user name and "FileName" with the name you want to give to the PDF file.
- Add the following code to send the PDF file as an attachment to the email:
Formula:
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Please find attached the PDF file."
On Error Resume Next
With OutMail
.To = Range("A1").Value 'Replace A1 with the cell that contains the email address
.Subject = "PDF file"
.Body = strbody
.Attachments.Add ("C:\Users\YourUserName\Documents\FileName.pdf") 'Replace with the actual path and file name of the PDF file
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Replace "A1" with the cell that contains the email address, and replace the path and file name of the PDF file with the actual path and file name.
- Save the code and close the VBA editor.
Now, when you click the button, it will print the active sheet to a PDF file and then send the PDF file as an attachment to the email address specified in the cell you have specified.