How to use Foxit ActiveX with Visual Basic Application
Option A:
- Open Excel or Access
- Select DEVELOPER->Visual Basic
- In the Microsoft Visual Basic for applications, select Tools->Reference->Browse…
- Browse to the folder where you have the Foxit ActiveX’s OCX located at and select the .ocx and press open, then press okay to add the reference.
- Foxit ActiveX comes in both x64 and x86 ocx. Repeat step 4 to add the other .ocx to the project.
- Go to DEVELOPER->Insert-> ActiveX Controls-> More Tools->choose FoxitPDFSDK Pro Control
- Select the region in the Excel or Access Sheet which you want the control to appear
- Go to the Visual Basic Editor
- Copy the following code to the “ThisWorkbook” of the project.
Sub OpenFile()
Dim ret
ret = Sheet1.FoxitPDFSDK1.OpenFile("E:\foxit\SE\test.pdf ", "")
Sheet1.FoxitPDFSDK1.FindFirst(“myTextString”, False, False)
Sheet1.FoxitPDFSDK1.GoToPage (0)
End Sub
9. Change the page in the code from "E:\foxit\SE\test.pdf" to an existing path on your machine.
10. Save and run it using the run button in Visual Basic Editor.
Option B:
1. Open Excel or Access
2. Select DEVELOPER->Visual Basic
Note: If you do not have the Developer tab. Go to File->Option->Customize Ribbon-> Check the Developer tab to add it
3. In the Microsoft Visual Basic for applications, select Tools->Reference->Browse…
4. Browse to the folder where you have the Foxit ActiveX’s OCX located at and select the .ocx and press open, then press okay to add the reference.
Note: You may need to change the file type to .ocx to see the ocx file.
5. Foxit ActiveX comes in both x64 and x86 ocx. Repeat step 4 to add the other .ocx to the project.
6. In the Project View, select ThisWorkbook and copy and paste the code below.
Sub AddFoxitPDFSDKPro()
Dim Target As Range
Set Target = Cells(1, 4)
Set WSheet = ThisWorkbook.Worksheets("Sheet1")
Set MyPDFSDK = WSheet.OLEObjects.Add(ClassType:="Foxit.FoxitPDFSD KProCtrl.5", Link:=False, DisplayAsIcon:=False, Left:=Target.Left, Top:=Target.Top, Width:=400, Height:= 600)
End Sub
Sub OpenFile()
Dim ret
ret = Sheet1.FoxitPDFSDK1.OpenFile("E:\foxit\SE\f20.pdf" , "")
Sheet1.FoxitPDFSDK1.GoToPage (2)
End Sub
7. Make changes to the code below to match the path of a PDF on your desktop
ret = Sheet1.FoxitPDFSDK1.OpenFile("E:\foxit\SE\f20.pdf" , "")
8. Run the code by pressing the play/run button
Note: Select the Object Browser Icon to see full list of features.
Leave a comment: