VBA to attach more than one PDF to email

Padthelad

Board Regular
Joined
May 13, 2016
Messages
64
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am running a Macro to attach the active sheet to an email as a PDF. I also want to be able to add another PDF from a network drive. I have tried to splice the code from another Macro I use to attach a specific file.

Code:
       'Add the active workbook as an attachment
OlMail.Attachments.Add "K:\Timber Buildings\2016 CUSTOMER JOB FILES\Terms and Conditions 2016.pdf"

The code I am using for the 'attach active sheet as PDF' is:-

Code:
Sub AttachActiveSheetPDF()
  Dim IsCreated As Boolean
  Dim i As Long
  Dim PdfFile As String, Title As String
  Dim OutlApp As Object
 
  ' Not sure for what the Title is
  Title = Range("B10")
 
  ' Define PDF filename
  PdfFile = ActiveWorkbook.FullName
  i = InStrRev(PdfFile, ".")
  If i > 1 Then PdfFile = Left(PdfFile, i - 1)
  PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
 
  ' Export activesheet as PDF
  With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, FileName:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
  End With
 
  ' Use already open Outlook if possible
  On Error Resume Next
  Set OutlApp = GetObject(, "Outlook.Application")
  If Err Then
    Set OutlApp = CreateObject("Outlook.Application")
    IsCreated = True
  End If
  OutlApp.Visible = True
  On Error GoTo 0
 
 
  ' Prepare e-mail with PDF attachment
  With OutlApp.createitem(0)
   

    .Subject = Title
    Dim Mailadress As String
Mailadress = CStr(Range("C40").Value)
.to = Mailadress
    .CC = ""
    .Body = "Dear," & vbLf & vbLf _
          & "Please find attached document" & vbLf & vbLf _
          & "Should you have any questions or queries, do not hesitate to contact ." & vbLf & vbLf _
          & "Kind regards," & vbLf & vbLf _
          & Application.UserName & vbLf & vbLf
    .Attachments.Add PdfFile
    


    On Error Resume Next
    .Display
    Application.Visible = True
    If Err Then
      MsgBox "E-mail was not sent", vbExclamation
    Else
      MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0
    
  End With
 
  Kill PdfFile
 
  If IsCreated Then OutlApp.Quit
 
  Set OutlApp = Nothing
 
End Sub

Can I combine the two commands to have an email that has the active sheet as pdf and also the file from the drive location?

Any help is very much appreciated as this is killing me not being able to figure it out!

Thanks,

Pad
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Just add another after the first.
Code:
.Attachments.Add PdfFile
.Attachments.Add "K:\Timber Buildings\2016 CUSTOMER JOB FILES\Terms and Conditions 2016.pdf"
 
Last edited:
Upvote 0
Just add another after the first.
Code:
.Attachments.Add PdfFile
.Attachments.Add "K:\Timber Buildings\2016 CUSTOMER JOB FILES\Terms and Conditions 2016.pdf"

Hi Kenneth,

I feel silly now! Thank you, I knew it was something simple.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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