Skip to content

Instantly share code, notes, and snippets.

@ElectricWarr
Created February 24, 2015 17:23
Show Gist options
  • Save ElectricWarr/43fd4ade56be33dc1ecf to your computer and use it in GitHub Desktop.
Save ElectricWarr/43fd4ade56be33dc1ecf to your computer and use it in GitHub Desktop.
Function ExcelToPDF ($workbook,$PDFdir) {
# Exports all worksheets of a PDF (except "Report" and "Template")
#Function Variables
[string] $filePath
#Set as saved
$workbook.Saved = $true
$xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type]
ForEach ($ws In $workbook.worksheets) {
If (!(($ws.Name -eq "Template") -or ($ws.Name -eq "Report"))) {
$filePath = Join-Path -Path $PDFdir -ChildPath ($ws.Name + ".pdf")
$ws.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filePath)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment