Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

STL - Formerly Best Training Solutions Through Learning
TrustPilot
Excellent
Request Callback We will call you back
0207 987 3777 Call for assistance
Your Basket Basket is empty
coding pdf

ResolvedVersion 2003

Jay has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

Coding to PDF

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

RE: Coding to PDF

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:

Jumping Across the Excel Screen

PgDn and PgUp keys scrolls up and down a screen page in most applications.

Alt+PgDn and Alt+PgUp is the equivalent across the spreadsheet.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.12 secs.