I am new to this forum, but the activity I have noticed reading the posts helps me believe this is a good spot for wannabes programmer like me.
I am also fairly new working under a windows environment, and even newer to work with OLE objects, so apologize (and plz correct me!) for anything wrong I might say. And maybe while I am it, would anyone be able to give a comprehensive explanations of what links OLE and COMs?
To my problem now, I am trying to program an application using Borland 5 that would connect to an Excel document, do some operations and retrieve the results.
Also, I am trying to make this application a little bit robust, so before trying to open Excel, I am checking if its not already active, and only if not I open it. My code is this:
Expand|Select|Wrap|Line Numbers
- try{ //Try to retrieve the application, if not opened, this would normally throw an error
- vMSExcel = Variant::GetActiveObject("Excel.Application");
- }
- catch(EOleSysError error1){ //Catch the error throwned when Excel is not opened
- try{ //Try to open Excel
- vMSExcel = Variant::CreateObject("Excel.Application");
- }
- catch(EOleSysError error2){ //Excel seems not to be installed
- ShowMessage("Unable to open Excel. Please make sure you have it installed.");
- }
- }
Now, when I compile, there are no warnings or error, but when I click the button, the problem I encouter is that the error created by GetActiveObject is not throwned (when the application is closed). Rather, a dialog box pops-up and tells it has received an error from EOleSysError and that the process is stopped. My first catch block is thus completely ignored.
I have tried to use catch(...), still without success.
Any thoughts/advices/help on this would be much appreciated,
Ras.