VBA late binding

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
anon5409742
User
Posts: 12
Joined: Wed Jan 27, 2021 3:31 pm

VBA late binding

Post by anon5409742 »

Hi,

I was able to code some interesting stuff using early binding in VBA (https://forum.pdf-xchange.com/viewtopic.php?f=67&t=35682&sid=8e0ff2e1361255bffe986201a74be1d8#p148211). Now I want to get rid of VBA References and use Late Binding to deploy my project.

This works:

Code: Select all

Dim objPXC          As New PDFXCoreAPI.PXC_Inst
Dim objDocMain      As IPXC_Document
Dim objDocSlaves    As IPXC_Document
Dim i               As Long


'initialization
objPXC.Init ""

Set objDocMain = objPXC.NewDocument()
Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(0), Nothing)

This DOES NOT work. It fails at "Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(0), Nothing)" because : 'Object doesn't support propert or method'

Code: Select all

Dim objPXC          As Object
Dim objDocMain      As Object
Dim objDocSlaves    As Object
Dim i               As Long

Set objPXC = CreateObject("PDFXCoreAPI.PXC_Inst")

'initialization
objPXC.Init ""

Set objDocMain = objPXC.NewDocument()
Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(0), Nothing)
Any ideas to try and fix this? I've tried a lot of things.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: VBA late binding

Post by Sasha - Tracker Dev Team »

Hello anon5409742,

Here's a small sample on VB6 that we had from earlier - please try using it:

Code: Select all

Dim objInst
Set objInst = CreateObject("PDFXCoreAPI.PXC_Inst")

'call objInst.GetExtension("AUX")
call objInst.Init("")
 
 Dim strMessage
 'strMessage = "API version:" + HiByte(HiWord(nVer)) + "." + LoByte(HiWord(nVer)) + "." +  HiByte(LoWord(nVer)) + "." + LoByte(LoWord(nVer)) + " (0x{"+ nVer.toString(16) + "})" 
strMessage = "API version: 0x" & hex(objInst.APIVersion) &"" 

Set objDocSlaves = objInst.OpenDocumentFromFile("E:\Temp\3.pdf", Nothing, Nothing, 0, 0)
call objDocSlaves.WriteToFile("D:\wer2.pdf", Nothing, 0)

objInst.Finalize()

MsgBox strMessage
Also, adding it as an attachment:
test.zip
(427 Bytes) Downloaded 130 times
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
anon5409742
User
Posts: 12
Joined: Wed Jan 27, 2021 3:31 pm

Re: VBA late binding

Post by anon5409742 »

there is a problem when using a string variable instead of passing the filepath directly.

This works:

Code: Select all

Set objDocSlaves = objPXC.OpenDocumentFromFile("C:\Users\user\AppData\Local\Temp\2021_02_16_EMDR_212977_Rapport de calibration.pdf", Nothing, Nothing, 0, 0)

This does not work and yield an error (Err 438, Object doesn't support this property or method.)

Code: Select all

file1 = arrayFilesPath(0)

Set objDocSlaves = objPXC.OpenDocumentFromFile(file1, Nothing, Nothing, 0, 0)
anon5409742
User
Posts: 12
Joined: Wed Jan 27, 2021 3:31 pm

Re: VBA late binding

Post by anon5409742 »

Nevermind, I just fixed my own problem.


If you force a string conversion, it works!!

Code: Select all

file1 = arrayFilesPath(0)
Set objDocSlaves = objPXC.OpenDocumentFromFile(CStr(file1), Nothing, Nothing, 0, 0)
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17823
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: VBA late binding

Post by Tracker Supp-Stefan »

Hello anon5409742,

Glad to hear that you have figured it out!
Thanks for sharing your solution.

Kind regards,
Stefan
anon5409742
User
Posts: 12
Joined: Wed Jan 27, 2021 3:31 pm

Re: VBA late binding

Post by anon5409742 »

Alright so the saga continues... I can't insert pages from another file and the sample code provided did not solve this problem:

This works in early binding:

Code: Select all

Dim objPXC          As New PDFXCoreAPI.PXC_Inst
Dim objDocMain      As IPXC_Document
Dim objDocSlaves    As IPXC_Document

objPXC.Init ""

Set objDocMain = objPXC.OpenDocumentFromFile(arrayFilesPath(0), Nothing)
Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(1), Nothing)

objDocMain.Pages.InsertPagesFromDoc objDocSlaves, objDocMain.Pages.Count, 0, objDocSlaves.Pages.Count, 0, Nothing

The following does not work in late binding. I get error 424, object required. I don't understand because all objects are declared and set

Code: Select all


Dim objPXC          As Object
Dim objDocMain      As Object
Dim objDocSlaves    As Object

Set objPXC = CreateObject("PDFXCoreAPI.PXC_Inst")
objPXC.Init ("")
Set objDocMain = objPXC.OpenDocumentFromFile(CStr(arrayFilesPath(0)), Nothing, Nothing, 0, 0)

Set objDocSlaves = objPXC.OpenDocumentFromFile(CStr(arrayFilesPath(1)), Nothing, Nothing, 0, 0)
Call objDocMain.Pages.InsertPagesFromDoc(objDocSlaves, objDocMain.Pages.Count, 0, objDocSlaves.Pages.Count, 0, Nothing)
Maybe I'm doing something wrong. Bottom line is, all I want to do is merge those document together.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: VBA late binding

Post by Sasha - Tracker Dev Team »

Hello anon5409742,

Forwarded this to the developer who can tell more. Hopefully we can find a solution for you.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: VBA late binding

Post by Sasha - Tracker Dev Team »

Hello anon5409742,

Everything worked correctly from your sample:

Code: Select all

Dim objPXC
Dim objDocMain
Dim objDocSlaves

Set objPXC = CreateObject("PDFXCoreAPI.PXC_Inst")
objPXC.Init ("")
Set objDocMain = objPXC.OpenDocumentFromFile(CStr("E:\TestFile\pdf\example_images.pdf"), Nothing, Nothing, 0, 0)

Set objDocSlaves = objPXC.OpenDocumentFromFile(CStr("E:\TestFile\pdf\example_barcode.pdf"), Nothing, Nothing, 0, 0)
Call objDocMain.Pages.InsertPagesFromDoc(objDocSlaves, objDocMain.Pages.Count, 0, objDocSlaves.Pages.Count, 0, Nothing)


call objDocMain.WriteToFile("D:\wer2.pdf", Nothing, 0)

objPXC.Finalize ()
Attaching the script file:
test2.zip
(373 Bytes) Downloaded 135 times
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
anon5409742
User
Posts: 12
Joined: Wed Jan 27, 2021 3:31 pm

Re: VBA late binding

Post by anon5409742 »

Thanks Sasha for the vbs. I tried it and it worked on my end too.

I think the problem is how VBA for Excel handles the variable qualifier and it seems different than how a VBS is handled and I don't know why or how...

Here is my local variables window when I use early binding. You can see the 'Type' being 'IPXC_Document/IPXC_Document'
early binding variable qualifier.png
early binding variable qualifier.png (5.92 KiB) Viewed 3977 times

When I use late binding, the variables 'Type' being 'Object/IPXC_Document'
late binding qualifier.png
late binding qualifier.png (5.92 KiB) Viewed 3977 times
Here the error I get on excel.
image.png
image.png (3.49 KiB) Viewed 3976 times
What I could find in Microsoft Doc about that error:
You supplied an object qualifier, but it isn't recognized as an object. Check the spelling of the object qualifier and make sure the object is visible in the part of the program in which you are referencing it. In the case of Collection objects, check any occurrences of the Add method to be sure the syntax and spelling of all the elements are correct.

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/object-required-error-424

Maybe someone has some hint on how to handle this?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: VBA late binding

Post by Sasha - Tracker Dev Team »

Hello anon5409742,

I've forwarded this one - hopefully we can assist.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply