How to call PDFPrint SDK to print a PDF file from MS Office VBA?

Hi
I have downloaded the trail version to see how it can be called from MS Access VBA.

The trail version do not contain an installation exe.
further,
I tried the VBA suggestion in folder VB.net\vb_net.txt, but it cant find the DLL.

How do i set this up in VBA, so I can call it.

Best regards
Customer
--------------------------
Thanks for your message, you may download the trial version of PDFPrint SDK from following web page first,

https://www.verypdf.com/app/pdf-print-cmd/try-and-buy.html#buy-sdk
https://www.verypdf.com/dl2.php/pdfprint_sdk.zip

after you download and unzip it to a folder, please go to "bin" folder, run install.vbs to install and register pdfprintcom.exe into your system, then you can run following VB Script Code to print a PDF file easily,

Set pdfcom = CreateObject("pdfprintcom.pdfprint")
nRet = pdfcom.com_PDFPrint("pdfprint D:\temp\1234.pdf")

VeryPDF

--------------------------

image

Visual Basic for Applications (VBA) and VBScript are both powerful scripting languages that can be used to automate tasks in various applications. Sometimes, you might need to call VBScript code from within your VBA environment to leverage the capabilities of both languages. In this article, we will walk you through the process of calling VBScript code from VBA, using a practical example.

Scenario

Suppose you have a VBScript code snippet that uses an external COM object to perform a specific task. In this case, we have a VBScript code snippet that utilizes the "pdfprintcom.pdfprint" COM object to print a PDF file located at "D:\temp\1234.pdf." We will demonstrate how to call this VBScript code from VBA.

Step 1: Create the VBScript File

First, create a new VBScript file with the following code:

Set pdfcom = CreateObject("pdfprintcom.pdfprint")

nRet = pdfcom.com_PDFPrint("pdfprint D:\temp\1234.pdf")

Save this file with a ".vbs" extension, such as "PrintPDF.vbs."

Step 2: Prepare the VBA Environment

Now, open your Microsoft Office application where you want to run the VBA code. For this example, we'll use Microsoft Excel. Follow these steps:

  1. Open Excel.

  2. Press ALT + F11 to open the VBA editor.

Step 3: Create a VBA Macro

Inside the VBA editor, you'll create a VBA macro that calls the VBScript code. Here's a sample VBA macro:

Sub CallVBScriptFromVBA()
Dim objShell As Object
Set objShell = CreateObject("WScript.Shell")
' Specify the path to your VBScript file
Dim vbscriptPath As String
vbscriptPath = "C:\Path\To\Your\PrintPDF.vbs"
' Run the VBScript code
objShell.Run "wscript.exe """ & vbscriptPath & """", 1, True
' Clean up
Set objShell = Nothing
End Sub

Make sure to replace "C:\Path\To\Your\PrintPDF.vbs" with the actual path to your VBScript file.

Step 4: Run the VBA Macro

To execute the VBA macro that calls the VBScript code:

  1. Close the VBA editor.

  2. Press ALT + F8 to open the "Macro" dialog box.
  3. Select "CallVBScriptFromVBA" from the list of macros.
  4. Click "Run."

The VBA macro will execute, which in turn runs the VBScript code, printing the specified PDF file.

Integrating VBScript code into your VBA environment can be a powerful way to leverage external resources and functionalities. By following the steps outlined in this article, you can seamlessly call VBScript code from VBA, expanding the capabilities of your automation scripts. This approach allows you to combine the strengths of both scripting languages to achieve your automation goals efficiently.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: +1 (from 1 vote)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!