Nearly finished setting up an auto-purchase order workbook. Last issue is that the uto exported and emailed pdf of a sheet is named after the workbook rather than the active sheet. Ideally, I would be able name the new pdf after an identified cell. See current code below.
VBA Code:
Public Sub Save_Range_As_PDF_and_Send_Email_PO()
Dim PDFrange As Range
Dim PDFfile As String
Dim toEmail As String, emailSubject As String
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim HTMLBody As String
With ActiveWorkbook
Set PDFrange = .ActiveSheet.Range("A1:I53")
toEmail = .ActiveSheet.Range("B15").Value
emailSubject = .ActiveSheet.Range("C6").Value
PDFfile = Replace(.FullName, ".xlsx", ".pdf")
End With
PDFrange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Send email with PDF file attached
Set OutApp = New Outlook.Application
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = toEmail
.Subject = emailSubject
.HTMLBody = "<p> Hello, </p>" & _
"<p> Please see attached purchase order. We are happy to connect to discuss an missing details. </p>" & _
"<p> Thank you, </p>" & _
"<p> rdc Procurement. </p>"
.Attachments.Add PDFfile
.send
End With
'Delete the temporary PDF file
Kill PDFfile
Set OutMail = Nothing
Set OutApp = Nothing
End Sub