Skip to content

Instantly share code, notes, and snippets.

Last active September 4, 2015 13:46
What would you like to do?
This short script creates a single PDF from a three-sheet Workbook
Option Explicit
Public Sub SaveSheetsAsPDF()
Dim wksAllSheets As Variant
Dim wksSheet1 As Worksheet
Dim strFilename As String, strFilepath As String
'Set references up-front
Set wksSheet1 = ThisWorkbook.Sheets("Sheet1")
wksAllSheets = Array("Sheet1", "Sheet2", "Sheet3")
strFilepath = "C:\blog\"
'Create the full Filename using cells D6, E6 and F6
With wksSheet1
'Assemble the string cell-by-cell, "D6 E6-F6"
strFilename = strFilepath & .Range("D6").Value & " " & _
.Range("E6").Value & "-" & _
.Range("F6").Value & ".pdf"
End With
'Save the Array of worksheets (which will be selected) as a PDF
wksSheet1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
'Make sure all the worksheets are NOT left selected
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment