HealthLinks is your destination for reliable, understandable, and credible health information and expert advice that always keeps why you came to us in mind.

How to Print PDF From Visual Basic

104 13
    • 1). Open your VB editor within a Microsoft document by clicking "Tools," "Macros," "Visual Basic Editor."

    • 2). Type the following code into the editor:

      Sub OpenPDF()

      Dim strPDFFileName As String

      strPDFFileName = "C:\examplefile.pdf"

      ('This next function checks to see if the file isn't already open)

      If Not FileLocked(strPDFFileName) Then

      (If it returns False, then continue opening the PDF file)

      Documents.Open strPDFFileName)

      End If

      End Sub

      Replace "strPDFFileName" with the full name of your PDF document. Replace "C:\examplefile.pdf" with the directory location of your document.

    • 3). Type the following code to prepare your PDF file for printing:

      Sub PrintPDF (strPDFFileName as string)

      Dim sAdobeReader as String

      sAdobeReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"

      RetVal = Shell(sAdobeReader & "/P" & Chr(34) & sStrPDFFileName & Chr(34), 0)

      End Sub

    • 4). Enter the below code to finally print your PDF document:

      Sub CommandButton_Click()

      Call OpenPDF

      Call PrintPDF

      End Sub

Source...

Leave A Reply

Your email address will not be published.