united2017
New Member
- Joined
- Jun 17, 2017
- Messages
- 17
- Office Version
- 365
- Platform
- Windows
Hi All, I have the below code to send the Print Area as a PDF to the E-mail address entered in the worksheet.
It was working all good initially and now states that "Outlook does not recognize one or more names" pointing to the ".send".
Also, is there a way this Macro can name the file "C2" & "-" & "F4"
It was working all good initially and now states that "Outlook does not recognize one or more names" pointing to the ".send".
Also, is there a way this Macro can name the file "C2" & "-" & "F4"
VBA Code:
Public Sub Send_Email_For_Print_Area()
Dim destFolder As String, PDFfile As String
Dim printRange As Range
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = New Outlook.Application
'PDF file for print range is temporarily saved in same folder as this workbook
destFolder = ThisWorkbook.Path & "\"
If Right(destFolder, 1) <> "\" Then destFolder = destFolder & "\"
If ActiveSheet.PageSetup.PrintArea <> "" Then
'Save print area for active sheet as a PDF file, file name from cell E2 and cell I7
PDFfile = destFolder & ActiveSheet.Range("f4").Value & ".pdf"
Set printRange = Range(ActiveSheet.PageSetup.PrintArea)
printRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Send email to address in cell O3 of active sheet with PDF file attached
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ActiveSheet.Range("O3").Value
.Subject = "Claim"
.Body = "Please find attached the claim for this month."
.Attachments.Add PDFfile
.Send
End With
'Delete the temporary PDF file
Kill PDFfile
Set OutMail = Nothing
Set OutApp = Nothing
End If
End Sub