Create PDF from VBA code

yankee428

Active Member
Joined
Apr 12, 2004
Messages
348
I have a user that wants to output Excel sheet to PDF file via VBA. Stupid desktop support has the PC locked down so we cannot install ANY 3rd party software. All the posts that I've come across in researching this project point to some type of 3rd party or addin that need to be installed. Is it possible to output to PDF w/o an extra utility?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I'm assuming you do have Acrobat installed though?

If so, Colo has some info on his page

http://puremis.net/excel/code/083.shtml

I've yet to try it as I'm waiting for acrobat to be installed but I'll be in exactly the same situation shortly.

The only other way I can think of is using sendkeys from vba but, as I say, I haven't tested any of it yet.

Nick
 
Upvote 0
Microsoft Office Excel provides many file format converters for importing and exporting data. However, Excel does not provide a file format converter for Adobe Portable Document Format (PDF), which is used with Adobe Acrobat products.

Office 2002 and above came with an adobe Add-in called Acrobat Distiller that must be installed in addition to Office. If yours did not you can get it here:

http://www.adobe.com/support/downloads/product.jsp?product=4&platform=Windows


It adds utilities to the toolbar that work with the product.

I thought there was talk that the newest version was to do this automatically, but I think MS backed out of the deal?

After market products do the same thing:

http://office.microsoft.com/en-us/marketplace/EM011155881033.aspx


A back-door way is to save the workbook as a web page, then use the full Acrobat product to convert the html to pdf.

Or for a static page do a print-screen capture to pdf.
 
Upvote 0
In order to create PDF with Adobe 6.0 Pro, you need to do the following:
Code:
Sub Create_PDF()

' Requires Acrobat Distiller 6.0
' and
' add VBA reference for Acrobat Distiller C:\Program Files\Adobe\Acrobat\Distillr\acrodist.exe

Dim PSFileName As String
Dim PDFFileName As String
Dim myPDF As New PdfDistiller

sPath = [rgPath]
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"

PDFFileName = sPath & [rgFile] & ".pdf"
PSFileName = "c:\temp\" & [rgFile] & ".ps"

Range("rgReport").PrintOut copies:=1, preview:=False, activeprinter:="Adobe PDF", _
    PrintToFile:=True, collate:=True, PrToFileName:=PSFileName
    
myPDF.FileToPDF PSFileName, PDFFileName, ""

Kill sPath & [rgFile] & ".log"

End Sub
 
Upvote 0
Can this code be modified to use CutePDF? I changed the ActivePrinter to ActivePrinter:="CutePDF Writer on CPW2:"

The Dim myPDF as New PdfDistiller is causing a problem. I tried changing to Dim myPDF as New CutePDF. That didn't work. Am I close???
 
Upvote 0

Forum statistics

Threads
1,215,579
Messages
6,125,646
Members
449,245
Latest member
PatrickL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top