Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
Last active September 4, 2015 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwagnerco/bae40caa6e218b9421f9 to your computer and use it in GitHub Desktop.
Save danwagnerco/bae40caa6e218b9421f9 to your computer and use it in GitHub Desktop.
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
ThisWorkbook.Sheets(wksAllSheets).Select
wksSheet1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
'Make sure all the worksheets are NOT left selected
wksSheet1.Select
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment