[COLOR=#000000][FONT=Arial]Option Explicit[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Sub SendAllSheetsWORKING()[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim ws As Worksheet[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]For Each ws In Worksheets[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ws.Activate[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] create_and_email_pdf[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Next[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Sub create_and_email_pdf()[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim EmailSubject As String, EmailSignature As String[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim CurrentMonth As String, DestFolder As String, PDFFile As String[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim Email_To As String, Email_CC As String, Email_BCC As String[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim OverwritePDF As VbMsgBoxResult[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]Dim OutlookApp As Object, OutlookMail As Object[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]CurrentMonth = ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]' *****************************************************[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]' ***** You Can Change These Variables *********[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] EmailSubject = "Invoice Attached for " 'Change this to change the subject of the email. The current month is added to end of subj line[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] OpenPDFAfterCreating = False 'Change this if you want to open the PDF after creating it : TRUE or FALSE[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] AlwaysOverwritePDF = False 'Change this if you always want to overwrite a PDF that already exists :TRUE or FALSE[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] DisplayEmail = True 'Change this if you don't want to display the email before sending. Note, you must have a TO email address specified for this to work[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Email_To = ActiveSheet.Range("A14") 'Change this if you want to specify To email e.g. ActiveSheet.Range("H1") to get email from cell H1[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Email_CC = ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Email_BCC = ""[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]' ******************************************************[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Prompt for file destination[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] DestFolder = "C:\Users\yourlocation"[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Current month/year stored in H6 (this is a merged cell)[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] CurrentMonth = Mid(ActiveSheet.Range("D8").Value, InStr(1, ActiveSheet.Range("D8").Value, " ") + 1)[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Create new PDF file name including path and file extension[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] PDFFile = DestFolder & Application.PathSeparator & ActiveSheet.Range("A10") & " - " & ActiveSheet.Range("D8") & " - " & ActiveSheet.Range("F10") & ".pdf"[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'If the PDF already exists[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If Len(Dir(PDFFile)) > 0 Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If AlwaysOverwritePDF = False Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] OverwritePDF = MsgBox(PDFFile & " already exists." & vbCrLf & vbCrLf & "Do you want to overwrite it?", vbYesNo + vbQuestion, "File Exists")[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] On Error Resume Next[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'If you want to overwrite the file then delete the current one[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If OverwritePDF = vbYes Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Kill PDFFile[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] MsgBox "OK then, if you don't overwrite the existing PDF, I can't continue." _[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Exiting Macro"[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] On Error Resume Next[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Kill PDFFile[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If Err.Number <> 0 Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] MsgBox "Unable to delete existing file. Please make sure the file is not open or write protected." _[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Create the PDF[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] :=False, OpenAfterPublish:=OpenPDFAfterCreating[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Create an Outlook object and new mail message[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Set OutlookApp = CreateObject("Outlook.Application")[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] Set OutlookMail = OutlookApp.CreateItem(0)[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] 'Display email and specify To, Subject, etc[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] With OutlookMail[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .Display[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .To = Email_To[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .CC = Email_CC[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .BCC = Email_BCC[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .Subject = EmailSubject & CurrentMonth[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .Attachments.Add PDFFile[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] If DisplayEmail = True Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] .Display[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial] End With[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]End Sub[/FONT][/COLOR]