![]() |
|
#1
|
|||
|
|||
|
Hi everyone,
I'm trying to develop a VB project to work with CDR files. I built the project with VBA for CorelDRAW11 and it works fine. The problem is that when I try to put everything in a VB project the "opendocument" method doesn't work (note: the goal is to get something that I can deliver to a customer without him being able to modify anything; if you have other suggestions they are very welcomed). The "wrong" line that works fine in VBA is the following: Dim doc As Document Set doc = OpenDocument("C:\test.cdr") When I put this lines in a VB project I code them as follows: Dim doc As Document Dim cdr As CorelDRAW.Application Set cdr = CreateObject("CorelDRAW.Application.11") Set doc = OpenDocument("C:\test.cdr") But in this case CorelDraw opens but hangs on the open document dialog (that is if I switch to CorelDRAW I find the opendocument dialog open but with no filename in it). Any clue? Thanks a lot Stefano |
|
#2
|
|||
|
|||
|
Do you have CorelDraw in your tools/references? That was the thing for me recently. I had a Front Page thing I needed to put in CorelDraw and I had to add Front Page to my references (as clued in by Alex) and use the frontpage.what.ever in place of application.what.ever since I was in another application other that the one using that VBA. I hope that made sense.
![]() Try that I bet it will work ________ HARLEY-DAVIDSON XLCR Last edited by Steve; 12-03-2011 at 00:32. |
|
#3
|
|||
|
|||
|
Unfortunately... I do.
Just to be sure: do you mean that if you run the VB code I wrote in my mail CorelDraw starts and opens the file without any problem? In the Project->References list I can see "Corel - CorelDraw 11.0 Library" checked. In fact CorelDraw regularly opens when VB executes the CreateObject("CorelDRAW.Application.11") statement, but then the OpenDocument command only opens the "File Open" dialog of CorelDraw and... that's it. If I click on the VB window I then get a "Component Request Pending" dialog stating that CorelDraw is not responding. Any more clue? |
|
#4
|
|||
|
|||
|
On my front page macro, I borrowed some code from the microsoft site. I'll give you the code and maybe you can pick it apart for use with your application. Remember that this was from Corel to Front Page so it's not copy/paste/go.
Code:
Dim myFPApp As frontpage.Application
On Error GoTo ErrorHandler
Set myFPApp = GetObject(, "FrontPage.Application")
myFPApp.CommandBars.FindControl(ID:=303).Execute
Exit Sub
ErrorHandler:
If Err.Number = 429 Then
'Error 429 is a "Can't Create Object" error
'This means that an instance of FrontPage is not running
'Therefore, create an instance of FrontPage
Set myFPApp = CreateObject("FrontPage.Application")
myFPApp.WebWindows(0).Visible = True
End If
frontpage.LocatePage "c:\...\index.htm", fpPageViewDefault
Let me know if it helped. Also, Alex is great at this stuff. I'm sure he'll step in here any minute.. any second.. uhh ![]() ________ Y125Z Last edited by Steve; 12-03-2011 at 00:32. |
|
#5
|
||||
|
||||
|
Hi Stefano,
I just did some tests and OpenDocument works correctly on my machine. I tested it with Draw 11 and the document was opened without any dialogs from a stand-alone VB program. One thing to look for though is the presence of CorelDRAW 9 or 10 on the same system. There were some interface changes between Draw 10 and 11 which caused binary incompatibility between the two versions. Most of the time it works fine however there is a catch. Both CorelDRAW 9 and 10 used to register its type library each time you launch the application. Due to Microsoft Windows logo requirements, CorelDRAW 11 doesn't do it at run-time, instead, its type library is registered only when you install the application. However if you run CorelDRAW 10 or 9 after you installed Draw 11, it will overwrite the type registration information (interface entries under HKEY_CLASSES_ROOT\Interface key in the system registry) which will point to the type library of Draw 10 or 9. When you make calls from out-of-process (such as stand-alone VB programs), the interface registration information is used for interprocess call marshaling but because the key points to an old type library, wrong information is used by COM and the calling process may even crash because of that. Whenever you notice that something is working in VBA but not VB, that's probably because of some issues of interprocess communication. The first thing to look for is to see, what version of the type library CorelDRAW interfaces are registered with. To check this, go to Registry editor and inspect the following key for example: HKEY_CLASSES_ROOT\Interface\{F51A0000-8D23-11D2-89E7-0000861EBBD6} This is the registry entry for the Application object interface. When you look at its TypeLib subkey you will see a Version value. It should be b.0 for CorelDRAW 11 (see the attached screenshot). If you see a.0, or 9.0 instead, then you have Draw 10 or 9 taken over the registration information. The best way to correct this problem is to re-register CorelDRAW 11's type library. You can do this either by re-installing Draw 11 (you may try "Repair Installation" option in the setup) or try to register it manually. To register it manually, you will need Visual Basic or you can use VBA in any other application aside from CorelDRAW itself. Here is what you need to do:
After you do this, Draw 11 should now work normally (untill you launch Draw 10 or 9 again ).I hope this helps. |
|
#6
|
|||
|
|||
|
Thanks a lot Alex,
indeed I had to run COrelDRAW10 after I installed CorelDRAW11. Modifying the registry key instantly solved the problem. I could have never even imagined that the solution was this complex (to find) and this simple (to solve). Now a have a similar problem with VBA: when I run the macro from CorelDRAW the file opens but the the macro exits with no further elaboration going on... Is there a CS command that I can run from VBA to open the file? I have the impression that Corel put a lot more effort in CS than in the VBA interface. Anyway, if there are no solutions to this second problem I can still run eveything from a VB project. Thanks again Stefano |
|
#7
|
||||
|
||||
|
Quote:
Quote:
|
|
#8
|
|||
|
|||
|
As you were suggesting, something wrong was happening because of the location in which the VBA macro was stored. Indeed, the macro was both stored in the document I had open and in the document I wanted to open. This fact was causing some interferences stopping the macro after that the new document was open. I moved the macro to a GMS project, removed the macro from the document I wanted to open, and now everything works fine: the new document opens and the macro keeps going.
Thanks Stefano |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| delete vba project from cdr file | hotairballoon | CorelDRAW/Corel DESIGNER VBA | 1 | 18-05-2005 09:08 |
| Work with BITMAP in Corel | drg | CorelDRAW/Corel DESIGNER VBA | 3 | 16-01-2005 09:29 |
| Whether the VBA can work with Unicode . | Dino | CorelDRAW/Corel DESIGNER VBA | 5 | 27-08-2003 16:13 |
| VBA does not work with my CD 10 ! | jobar | CorelDRAW/Corel DESIGNER VBA | 1 | 24-08-2003 12:38 |
| Looping layers: Why doesn't this work? | andyb | CorelDRAW/Corel DESIGNER VBA | 1 | 10-07-2003 18:41 |