Results 1 to 2 of 2

Thread: Excel To PDF Using VB

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Game Over, Man!
    Posts
    36

    Lightbulb Excel To PDF Using VB

    I have used the following VB code to print an Excel range to an Adobe Acrobat .PDF file. The steps to accomplish this are as follows:

    1. Print the range to a postscript file using Acrobat Distiller
    2. Convert postscript file to .PDF using Acrobat Distiller API.

    Make sure that you uncheck the "Do not send fonts to Distiller" option in the Distiller properties. You do this by entering the Distiller properties>>General Tab>>Printing Preferences>>Adobe PDF Settings and uncheck the "Do not send fonts to Distiller" option. You will get an error if you don't do this.

    In the Excel Visual Basic Editor, make sure you include a reference to Acrobat Distiller.

    Here is the code....

    *********************************************
    Private Sub CommandButton1_Click()

    ' Define the postscript and .pdf file names.
    Dim PSFileName as String
    Dim PDFFileName as String
    PSFileName = "c:\myPostScript.ps"
    PDFFileName = "c:\myPDF.pdf"

    ' Print the Excel range to the postscript file
    Dim MySheet As WorkSheet
    Set MySheet = ActiveSheet
    MySheet.Range("myRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prttofilename:=PSFileName

    ' Convert the postscript file to .pdf
    Dim myPDF As PdfDistiller
    Set myPDF = New PdfDistiller
    myPDF.FileToPDF PSFileName, PDFFileName, ""

    End Sub

    *********************************************

    And that is all there is to it! I hope this tip is helpful to some of you.

  2. #2
    New Member
    Join Date
    Jan 2002
    Location
    Wisconsin
    Posts
    11

    Question PLT to PDF

    I am new at this so please be patient with me. I am trying ot do something similar to what you have done in excel but I am using a .plt file instead of and excel file.

    I referenced Acrobat Distiller in VB and wrote the following code:

    Private Sub Command1_Click()
    Dim PSFileName As String
    Dim PDFFileName As String
    PSFileName = "c:\mytest.plt"
    PDFFileName = "c:\mytest.pdf"

    Dim myPDF As PdfDistiller
    Set myPDF = New PdfDistiller

    myPDF.FileToPDF PSFileName, PDFFileName, ""

    End Sub

    When i run my routine I get an ActiveX component cannot ceate object.

    I hangs on the line: Set myPDF = New PdfDistiller

    Do you have any ideas what I am doing wrong.

    Any help would be appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width