Oh where, oh where is Excel?
I am writing an application that saves data to a comma-delimited file. I want to be able to export this data to Microsoft Excel so that the user can do something useful with it. I am writing the application in C++. I have tried using WinExec, CreateProcess, and SearchPath to locate and run Microsoft Excel. None of these system calls are able to find Excel because it is not in the path. (Although in Windows 95, I can start Excel from "Start-Run" and it can find Excel.) Is there a generic way to find out if Excel is on the computer and where it is located?
Jason Carnahan
Oy! Another location and forwarding question! Dr. GUI isn't a mail service. He's not even sure he's a male service sometimes. Oops. Another programming question.
Well, Dr. GUI is pleased to say that he has a most Excel-lent way to start up Microsoft Excel, regardless of where it's located.
The ShellExecute function in the Microsoft Platform SDK (formerly called the Win32 SDK) will fire off Microsoft Excel (or any other application). Better yet, you can even pass it the filename of a document, and Microsoft Excel will load up that document's application automatically. In your case, if you do the following:
ShellExecute(<Window handle>, NULL, "Excel", NULL, NULL, SW_SHOWNORMAL);
and if Microsoft Excel is properly installed on the user's system, then Microsoft Excel will load. (You'll want to do some error checking to make sure it loaded okay, of course.)
If you really want to, you can also find the location of the Microsoft Excel .exe file by using the Windows API FindExecutable. But for most uses, using ShellExecute is easier.