OberonPlace.com Forums  

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

Thread Tools Search this Thread Display Modes
Old 24-07-2009, 09:00
Posts: n/a
Default Using ActiveDocument.SaveAs (c#)

I am trying to use the ActiveDocument.SaveAs command and I'm not suer how to go about it.

The second parameter is what has me confused - StructSaveAsOptions.

I try to declare a variable of this type object, which works fine. Then I try to set the overwrite value to false. This complies fine but throws an error at runtime saying the cast was not correct which confuses me since it says this overwrite object is of type bool. Anyway, here is my code. I just want it to save the darn document. Any advice or pointers would be great.

CorelDRAW.Application corel_app = new CorelDRAW.Application();
corel_app.Visible = true;
corel_app.ActivePage.SizeHeight = 18;
corel_app.ActivePage.SizeWidth = 32;
CorelDRAW.StructSaveAsOptions options = new CorelDRAW.StructSaveAsOptions();
//options.Overwrite = false;
corel_app.ActiveDocument.SaveAs("c:\\Test.cdr", options);

I know that I'm just trying to save a blank sheet here, for now I'm just trying to understand the proper way to do it. With the next to last line commented out I get a cast error on the SaveAs Line. With the next to last option not commented out I get a cast error on that line. But again, this code compiles just fine. Any help would be greatly appreciated.

Reply With Quote
Old 27-07-2009, 09:56
Posts: n/a

I figured i would add some more detail on this issue.
Here is the exception that is thrown when i try and set one of the attributes of my StructSaveAsOptions object...
Unable to cast COM object of type 'CorelDRAW.StructSaveAsOptionsClass' to interface type 'CorelDRAW.IStructSaveAsOptions'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{F51A0207-8D23-11D2-89E7-0000861EBBD6}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

If I create the object, don't set any attributes, and run it, the actual Save as Line Throws a InvalidCastException with the error Specified Cast is not valid.

Once again, any help would be greatly appreciated. Thanks.
Reply With Quote
Old 28-07-2009, 08:39
Posts: n/a

I have figured out my problem, and I thought i would post it here incase someone else stumbles across the same issue. Keep in mind i was making a C# based windows form in Visual Stuio 2008.
The issue was in the way I was declaring the StructSaveAsOptions.
I was trying this...

CorelDraw.StructSaveasOptions tmp = new CorelDraw.StructSaveAsOptions();

Now this did compile okay, but when i ran it it would crash whenever i tried to change any attributes of tmp or try and use it in the ActiveDocument.SaveAs routine. What I should have been doing to create this object was this...

CorelDraw.Application corel_app = new CorelDraw.Application();
CorelDraw.StructSaveAsOptions Save_options = corel_app.CreateStructSaveAsOption();

I guess the second way I'm binding thos save as options to the application, whereas in the first method i am not. Anyway, ran my code with the new declaration in it, and Wah-Lah, it works.
Reply With Quote

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
RunMacro in the ActiveDocument pafi Macros/Add-ons 1 25-01-2010 09:45
How to Get a ActiveDocument Unit .... 3dvr CorelDRAW/Corel DESIGNER VBA 1 27-10-2008 11:11
saveas problems.. silviopr CorelDRAW/Corel DESIGNER VBA 2 29-01-2007 09:08
Help with ActiveDocument.PublishToPDF pbisson Corel Photo-Paint VBA 5 03-01-2007 20:37
Help with ActiveDocument.PublishToPDF pbisson Macros/Add-ons 0 15-12-2006 16:27

All times are GMT -5. The time now is 09:21.

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