Send pdf by email using VBA

tigerdel

Board Regular
Joined
Oct 13, 2015
Messages
122
Office Version
  1. 365
Platform
  1. Windows
I have the code below but at the Filters line it gives me an error of Complie Error: Argument not optional

Code:
Sub create_and_email_pdf()
Dim EmailSubject As String, EmailSignature As String
Dim CurrentMonth As String, DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult
Dim OutlookApp As Object, OutlookMail As Object
Dim fullpath As String
Dim Cn As Variant
    EmailSubject = "Quotation Attached"
    OpenPDFAfterCreating = False
    AlwaysOverwritePDF = False
    DisplayEmail = True
    'Email_To = 'Sheets("Quotation").Range("I1")   'Change this if you want to specify To email e.g. ActiveSheet.Range("H1") to get email from cell H1
    Email_CC = ""
    Email_BCC = ""
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .InitialFileName = Environ$("OneDrive") & "\MJM Services\2.0 Quotations\pdf Copy\"
        .Title = "Select the file to email"
        .Filters.Add " *.pdf"
        If .Show <> -1 Then Exit Sub
        fullpath = .SelectedItems.Item(1)
    End With
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    With OutlookMail
        .Display
        .To = Email_To
        .CC = Email_CC
        .BCC = Email_BCC
        .Subject = EmailSubject
        .Attachments.Add PDFFile
        If DisplayEmail = False Then
     .Send
End If
End With
End Sub

Any help with this would be very welcome

Thanks for looking
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,083
Two arguments are required:

1602284897270.png
 
Solution

Forum statistics

Threads
1,147,517
Messages
5,741,631
Members
423,674
Latest member
Charles2dodo

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
Top