Searching for Excel

I’m working on an application for Windows that exports data out to an Excel workbook. Given this requirement, it’s clearly necessary that Excel be installed on the machine, so I’m trying to verify that it is. It seems that the easiest way to do this is to try to create an instance of Excel and if successful, the application could continue. Otherwise, it should fail with an error. Here’s the code I’m using to check it:

Dim obj as OLEObject

try
obj = New OLEObject(“Excel.Application”,true)
obj = nil
catch err as OLEException
MsgBox “Microsoft Excel is not installed!”
end try

Then, I renamed the EXCEL.EXE file to XEXCEL.EXE to make the application think that Excel is not installed.

When I RUN the application to debug, it craps out at the New declaration with an OLEException. The try/catch does nothing. I have to Resume the action for the catch to display the MsgBox. However …

When I BUILD the application and run it, it works perfectly (the MsgBox is displayed as it should be)!

Am I missing something? Thanks!

Sounds like you have “Break on Exceptions” checked in the Xojo IDE, which would be why it’s breaking on that exception.

You can also add:

#pragma breakonexceptions false

To turn that off at the top of your method.

Its not but that is simplest
You can write a suitably formatted HTML file + extension
A BIFF file
Or one of the XML formats without any help from Excel

Opening it is a different story

[quote=161755:@Michael Nagel]I’m working on an application for Windows that exports data out to an Excel workbook. Given this requirement, it’s clearly necessary that Excel be installed on the machine, so I’m trying to verify that it is. It seems that the easiest way to do this is to try to create an instance of Excel and if successful, the application could continue. Otherwise, it should fail with an error. Here’s the code I’m using to check it:

Dim obj as OLEObject

try
obj = New OLEObject(“Excel.Application”,true)
obj = nil
catch err as OLEException
MsgBox “Microsoft Excel is not installed!”
end try

Then, I renamed the EXCEL.EXE file to XEXCEL.EXE to make the application think that Excel is not installed.

When I RUN the application to debug, it craps out at the New declaration with an OLEException. The try/catch does nothing. I have to Resume the action for the catch to display the MsgBox. However …

When I BUILD the application and run it, it works perfectly (the MsgBox is displayed as it should be)!

Am I missing something? Thanks![/quote]

That will never work by renaming your “EXCEL.exe” to “XEXCEL.EXE” as test. As you are working with a registered activeX component. You will only be able to check if the activeX component of EXCEL is registered but not all the executables or dlls. You will need to check the Windows Registry if Excel is installed or check the directory path for “EXCEL.exe”

I don’t have Excel on this computer, so I tested your example. And here I got an error in code during the compiling.

I don’t know if this is an option for you, but I produce excel files without needing excel to be installed:
MBS plugin: http://www.monkeybreadsoftware.de/xojo/plugin-xls.shtml

It’s pretty easy and straightforward to use and comes with many examples to get you started.
As one needs to buy licenses (MBS and LibXL) it is not cheap, though.

But you don’t need MS Excel on the client’s computer …

http://libxl.com/purchase.html

maybe first download our plugin and check if it helps?

Or visit http://great-white-software.com/rblibrary/index.php?main_page=index&cPath=34