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
And then in the module (pdf one is created withing this module earlier in the code but I did post all that)
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