Hi, I have this VBA that works great. It convert a specific range in active worksheet and attaches as PDF to email. Now I'm trying to also add the same range to the body of the email. Any advise?
Sub SendPDF()
' Create PDF and send as attachment.
Dim strPath As String, strFName As String
Dim OutApp As Object, OutMail As Object
'Create PDF
strPath = Environ$("temp") & "" 'Or any other path, but include trailing ""
strFName = ActiveWorkbook.Name
strFName = Left(strFName, InStrRev(strFName, ".") - 1) & "_" & ActiveSheet.Name & ".pdf"
ActiveSheet.PageSetup.PrintArea = "$a$1:$h$25"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPath & strFName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Set up outlook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Create message
On Error Resume Next
With OutMail
.to = ""
.CC = ""
.BCC = ""
.Subject = "" & ActiveSheet.Name
.Body = "Hello," & vbCr & " " & ActiveSheet.Name & "." & vbCr & "Best regards," & vbCr & vbCr & ""
.Attachments.Add strPath & strFName
.Display
End With
'Delete any temp files created
Kill strPath & strFName
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Sub SendPDF()
' Create PDF and send as attachment.
Dim strPath As String, strFName As String
Dim OutApp As Object, OutMail As Object
'Create PDF
strPath = Environ$("temp") & "" 'Or any other path, but include trailing ""
strFName = ActiveWorkbook.Name
strFName = Left(strFName, InStrRev(strFName, ".") - 1) & "_" & ActiveSheet.Name & ".pdf"
ActiveSheet.PageSetup.PrintArea = "$a$1:$h$25"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPath & strFName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Set up outlook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Create message
On Error Resume Next
With OutMail
.to = ""
.CC = ""
.BCC = ""
.Subject = "" & ActiveSheet.Name
.Body = "Hello," & vbCr & " " & ActiveSheet.Name & "." & vbCr & "Best regards," & vbCr & vbCr & ""
.Attachments.Add strPath & strFName
.Display
End With
'Delete any temp files created
Kill strPath & strFName
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub