NVRensburg
Board Regular
- Joined
- Jul 1, 2014
- Messages
- 100
- Office Version
- 365
- 2016
- Platform
- Windows
Hi there
Please could someone assist with adding an instruction to this VBA: I want to add the instruction of adding a specific range to the PDF namely ActiveSheet.PageSetup.PrintArea = "$P$2:$Z$15", but can't seem to get it right?
Sub SendPDF()
' Create PDF of active sheet and send as attachment.
'
Dim strPath As String, strFName As String
Dim OutApp As Object, OutMail As Object
'Create PDF of active sheet only
strPath = Environ$("temp") & "\" 'Or any other path, but include trailing "\"
strFName = ActiveWorkbook.Name
strFName = Left(strFName, InStrRev(strFName, ".") - 1) & "_" & ActiveSheet.Name & ".pdf"
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 = "***email address removed***" 'Insert required address here ########
.CC = ""
.BCC = ""
.Subject = "Insert Subject Text Here"
.Body = "Insert Body Text Here." & vbCr & "Best regards, etc." & vbCr
.Attachments.Add strPath & strFName
.Display 'Use only during debugging ##############################
'.Send 'Uncomment to send e-mail ##############################
End With
'Delete any temp files created
Kill strPath & strFName
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Please could someone assist with adding an instruction to this VBA: I want to add the instruction of adding a specific range to the PDF namely ActiveSheet.PageSetup.PrintArea = "$P$2:$Z$15", but can't seem to get it right?
Sub SendPDF()
' Create PDF of active sheet and send as attachment.
'
Dim strPath As String, strFName As String
Dim OutApp As Object, OutMail As Object
'Create PDF of active sheet only
strPath = Environ$("temp") & "\" 'Or any other path, but include trailing "\"
strFName = ActiveWorkbook.Name
strFName = Left(strFName, InStrRev(strFName, ".") - 1) & "_" & ActiveSheet.Name & ".pdf"
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 = "***email address removed***" 'Insert required address here ########
.CC = ""
.BCC = ""
.Subject = "Insert Subject Text Here"
.Body = "Insert Body Text Here." & vbCr & "Best regards, etc." & vbCr
.Attachments.Add strPath & strFName
.Display 'Use only during debugging ##############################
'.Send 'Uncomment to send e-mail ##############################
End With
'Delete any temp files created
Kill strPath & strFName
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub