Formerly Best Training
© 2024 STL. All Rights Reserved.
All prices offered for business users and exclude VAT. E&OE
2nd Floor, CA House, 1 Northey Street, Limehouse Basin, London, E14 8BT. United Kingdom
Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Coding to PDF
Resolved · Medium Priority · Version 2003
Jay has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Hi, I was wondering if it is possible to write some code to save a file and print PDF but more importantly save it down into a specified location. I can produce the PDF fine but having trouble saving it to a specific folder.
Thanks
Hi Jay, thanks for your query. Writing code to printing to PDF depends a lot on the PDF software you use. The subroutine below assumes you are using Adobe Acrobat and will PDF and save each individual worksheet in the workbook in a location of your choice. Amend as necessary to PDF specific worksheets and save them where needed. Here's the code:
*******************
Option Explicit
Sub pdfme()
'need to check Reference to Acrobat Distiller in Tools --> References
'select file - print - adobe pdf - properties and untick "Do not send fonts to Adobe PDF"
Dim shtSheet As Worksheet
Dim myworksheetname As String
Dim PSFileName As String
Dim PDFFileName As String
Dim myPDF As PdfDistiller
Application.DisplayAlerts = False
Set myPDF = New PdfDistiller
For Each shtSheet In ActiveWorkbook.Worksheets
shtSheet.Select
myworksheetname = ActiveSheet.Name
PSFileName = "c:\mypdfs\" & myworksheetname & ".ps"
PDFFileName = "c:\mypdfs\" & myworksheetname & ".pdf"
'Print the Excel range to the postscript file
ActiveWindow.SelectedSheets.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
printtofile:=True, collate:=True, prtofilename:=PSFileName
'Convert the postscript file to .pdf
DoEvents
myPDF.FileToPDF PSFileName, PDFFileName, ""
DoEvents
Next shtSheet
Application.DisplayAlerts = True
End Sub
*******************
Hope this helps,
Anthony
Wed 19 Jan 2011: Automatically marked as resolved.
|
Excel tip:Checking formulas with multiple operatorsWhen dealing with formulas containing more than one operator (+, -, /, *), Excel follow standard BEDMAS order of operation rules. These rules specify the order that calculations will be performed in, regardless of how the formula reads left to right: |
We'll call during UK business hours
Server loaded in 0.08 secs.