Page 1 of 1

VBA late binding

Posted: Tue Feb 02, 2021 8:27 pm
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.

Re: VBA late binding

Posted: Thu Feb 04, 2021 11:36 am
by Sasha - PDF-XChange
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
Cheers,
Alex

Re: VBA late binding

Posted: Tue Feb 16, 2021 4:53 pm
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)

Re: VBA late binding

Posted: Tue Feb 16, 2021 4:57 pm
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)

Re: VBA late binding

Posted: Tue Feb 16, 2021 5:00 pm
by Stefan - PDF-XChange
Hello anon5409742,

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

Kind regards,
Stefan

Re: VBA late binding

Posted: Tue Feb 16, 2021 6:10 pm
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.

Re: VBA late binding

Posted: Tue Feb 16, 2021 7:05 pm
by Sasha - PDF-XChange
Hello anon5409742,

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

Cheers,
Alex

Re: VBA late binding

Posted: Wed Feb 17, 2021 9:38 am
by Sasha - PDF-XChange
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
Cheers,
Alex

Re: VBA late binding

Posted: Wed Feb 17, 2021 10:41 pm
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

When I use late binding, the variables 'Type' being 'Object/IPXC_Document'
late binding qualifier.png
Here the error I get on excel.
image.png
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?

Re: VBA late binding

Posted: Fri Feb 19, 2021 8:55 am
by Sasha - PDF-XChange
Hello anon5409742,

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

Cheers,
Alex

Re: VBA late binding

Posted: Fri May 16, 2025 7:02 pm
by TH_ScottC
Ran into this same thing. Was this issue ever resolved?

Re: VBA late binding

Posted: Thu May 22, 2025 8:35 pm
by Daniel - PDF-XChange
Hello, TH_ScottC

Sadly I am unsure of the status of this, whether it was fixed or not. I have reached out to the team, and one of our Developers will be checking into this soon.

Kind regards,

Re: VBA late binding

Posted: Thu May 22, 2025 9:13 pm
by Roman - Tracker Supp
The issue will be resolved in the next release of the Editor.