This short script creates a single PDF from a three-sheet Workbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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