coding pdf
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Coding to PDF

Coding to PDF

resolvedResolved · Medium Priority · Version 2003

replyReply Wed 12 Jan 2011, 10:32Delegate Jay said...

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

For upcoming training course dates see: Pricing & availability

replyReply Wed 12 Jan 2011, 14:52Trainer Anthony said...

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.

 

Please browse our web site to find out more about
excel consulting and other Microsoft training courses.

Excel tip:

Quickly copy a formula across sheets

Suppose you have a formula in cell Sheet1!B2, say =A1*5%, that you wish to copy to cell B2 on Sheet2, Sheet3 and Sheet4. Instead of using copy and paste, try this: (1) Select Sheet1!B2. (2) Group Sheet1 with the worksheets Sheet2, Sheet3 and Sheet4 by holding down Ctrl and clicking on the tabs of the sheets to group them. (3) Press the F2 key, then immediately press Enter to copy the formula in Sheet1!B2 across the grouped sheets.

Remember to ungroup the sheets afterwards! Right-click on any tab and choose Ungroup Sheets to do that.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard