Define PDF file and attache to mail

Johnnyboy1x

New Member
Joined
Jan 11, 2013
Messages
32
Hello All --

In a user form I define a PDF file and it is created successfully.

In a seperate module, I define another PDF file and it too is created successfully and attahced to an outlook mail.

I want both PDF's to attach to the mail but have been unsuccessful in doing so thus far.

Code is below. If fails at add.attachment......PDFfile2. Pdffile 1 does attach successfully

Any thoughts are appreciatted. Code Bleow

Thanks, John

User Form
Rich (BB code):
Private Sub cbARCOS2_Click()
Sheets(Array("ARCOS 2")).Select
End Sub
 
Private Sub CommandButton1_Click()
  ' Define PDF filename
  PdfFile2 = Environ("temp") & "\" & ActiveWorkbook.FullName
  i = InStrRev(PdfFile2, ".")
  If i > 1 Then PdfFile2 = Left(PdfFile2, i - 1)
  PdfFile2 = Sheets("Service Report").Range("H12") & " - " & Sheets("Service Report").Range("C9") & " - " & Sheets("Service Report").Range("H11") & " - " & Sheets("Service Report").Range("G4") & " - " & "PM Checklist" & ".pdf"
  
  ' Export sheet(s) as PDF
 
     With ThisWorkbook.ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=Environ("temp") & "\" & PdfFile2, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With
Unload Me
End Sub


And then in the module (pdf one is created withing this module earlier in the code but I did post all that)

Rich (BB code):
  ' 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
  OutMail.Visible = True
  On Error GoTo 0
 
 ' Prepare e-mail with PDF attachment
  With OutlApp.CreateItem(0)
 
   
    ' Prepare e-mail
    .Subject = Title
    .To = Sheets("Service Report").Range("C14").Value '<-- Put email of the recipient here
    .cc = Sheets("Service Report").Range("C15").Value & ";" & " " & "Spectro-USA.ServiceInvoicing@ametek.com" ' <-- Put email of 'copy to' recipient here
    .HTMLBody = "Hello" & " " & Sheets("Service Report").Range("C12").Value & "," & "<br><br>" & _
           "Thank you for choosing SPECTRO.  Your service report is attached. Save the filled form attachment for your own records." & "<br><br>" & _
           "Regards," & " " & "<br><br>" & _
           Application.UserName & "<br><br>" & _
           "<a href='https://www.surveymonkey.com/r/NS96BH8'> How are we doing?  Survey takes less than 3 minutes. </a>"
 
 
    .Attachments.Add Environ("temp") & "" & PdfFile1
    .Attachments.Add Environ("temp") & "" & PdfFile2
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,376
Messages
6,119,175
Members
448,870
Latest member
max_pedreira

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