I am using CorelDRAW API within my VBA Application since years.For easier compiling and different version issues I recently changed from early to late binding. So now there is no reference to CorelDRAW.tlb necessary. After rebuilding hundreds of subs/functions everything works fine. But at the end, when exporting a document, the error 13 "type missmatch" occurs. I made many tests but could not find a problem in my code. Maybe this is a bug in the API itself?
Below a simple code, which could be tested in CorelDRAW VBA. From my point of view this code should normally work.
Private Sub Test_ExportEx_oDoc_as_Object() 'Late Binding Dim oApp As Object Dim oDoc As Object Dim oExpOpt As Object Dim oExpFlt As Object Dim sFile As String Set oApp = Application Set oDoc = oApp.ActiveDocument Set oExpOpt = oApp.CreateStructExportOptions oExpOpt.UseColorProfile = True sFile = "C:\temp\Test.eps" Set oExpFlt = oDoc.ExportEx(sFile, cdrEPS, cdrCurrentPage, oExpOpt) With oExpFlt .Finish End With End Sub
Has anybody experienced the same problem or a workaround? Please also respond if you can confirm, that this is likely might be a problem of the API itself.
I tried this with X7 and 2020.
You must not declare everything as Object!
I have no clue which VBA you are using, I tested it with Excel 2013. Here I faced even earlier a problem. But this was clear to me, because your script created – in my case – an Excel-Object. And Excel does not know many of the CorelDraw.Events, methods and properties.
So you first have to declare in your 'Master'-VBA the CorelDraw you are using. Go for that in VBA under Tools/References to the CorelDraw-Version in question and activate this reference.
Then you have to change your undefined objects in CorelDraw – Definitions. Then it should run: