Visual Basic Applications (VBA) designed by Microsoft use Visual 6 programming language. It was created for developers to enable user-defined functions and automate processes. It can be used to create a Word document from Excel and vice versa, as it is embedded in Microsoft Office applications. You can use VBA to print PDF files, if you understand the VBA language and editor.
- Skill level:
Other People Are Reading
Open your VBA editor with the document in which you wish to type the code. Click on "File," then hit "Tools." Click on "Macros." Hit "Visual Basic Editor." If using 2007 applications, click on "Developer," and then hit "Visual Basic."
Enter this code into the code window:
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)
Edit "strPDFFileName" add the full file name to the PDF file that you want to open. Replace "C:\examplefile.pdf" with the actual location path of your PDF document.
Type in this code to prepare to print your PDF:
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)
Modify the path in this code of the "Adobe Reader" to the actual path of your version.
Enter this code to trigger your PDF to print:
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for