OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 19-05-2003, 10:45
s_federici
Guest
 
Posts: n/a
Default opendocument doesn't work in a VB project

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
Reply With Quote
  #2  
Old 20-05-2003, 15:16
Steve
Guest
 
Posts: n/a
Default

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.
Reply With Quote
  #3  
Old 21-05-2003, 02:57
s_federici
Guest
 
Posts: n/a
Default

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?
Reply With Quote
  #4  
Old 21-05-2003, 21:57
Steve
Guest
 
Posts: n/a
Default

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
I hope that helps. It seems to me the big deal was the error direction.

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.
Reply With Quote
  #5  
Old 22-05-2003, 08:41
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: opendocument doesn't work in a VB project

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:
  1. Make sure CorelDRAW is not running
  2. In registry editor go to the following key: HKEY_CLASSES_ROOT\TypeLib\{FBF4300F-D921-11D1-B806-00A0C90646A9} - this is the type library entry for CorelDRAW. It will contain sub-keys such as "9.0", "a.0", "b.0" depending on what version you have installed on your system
  3. Delete the b.0 subkey
  4. Start Visual Basic and create a new project (or launch Photo-Paint or MS Word and go to VBA)
  5. In VB, go to Project>References dialog
  6. Click Browse button
  7. Navigate to C:\Program Files\Corel\Graphics Suite 11\Programs folder (or whatever it is you installed Draw 11 into) and select CorelDRW110.tlb
  8. Click OK and this should add the type library information back and re-register all the classes and interfaces in the type library

After you do this, Draw 11 should now work normally (untill you launch Draw 10 or 9 again ).

I hope this helps.
Attached Images
 
Reply With Quote
  #6  
Old 23-05-2003, 04:01
s_federici
Guest
 
Posts: n/a
Default Re: opendocument doesn't work in a VB project

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
Reply With Quote
  #7  
Old 23-05-2003, 07:58
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: opendocument doesn't work in a VB project

Quote:
Originally Posted by s_federici
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...
I don't have this problem either. It works here. Where did you put the macro in VBA? Is it in a project embedded in a document? Or is it in a GMS file (e.g. Global Macros)?

Quote:
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.
CorelScript is much less developed than VBA interface. There are A LOT of problems in CorelScript. Certainly you are better off using VBA
Reply With Quote
  #8  
Old 17-06-2003, 09:43
s_federici
Guest
 
Posts: n/a
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -5. The time now is 19:49.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com