- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the following code to invoke Excel, where filename is the name of the form name.csv.
However, it won't work if Excel is already open. Is ther any way to get around this?
If Excel is already open, I=SHELLEXECUTEEX(SEI) just returns immediately without any waiting. Otherwise it works fine.
CALL ZEROMEMORY(LOC(SEI),SIZEOF(SEI))
SEI.CBSIZE = SIZEOF(SEI)
SEI.FMASK = SEE_MASK_NOCLOSEPROCESS
SEI.LPFILE = %LOC(FILENAME)
I=SHELLEXECUTEEX(SEI)
IF (I .EQ. 0) THEN
I = GETLASTERROR()
ELSE
CALL SYSOUT('0Waiting for Excel to finish...\(If Excel fails to start you may already have it open and need to close it.)')
I = WAITFORSINGLEOBJECT(SEI.HPROCESS, INFINITE)
I = CLOSEHANDLE(SEI.HPROCESS)
END IF
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not know the behaviouir of ShellExecuteEx but I use CreateProcess to launch excel with a csv file and it does not care if excel is already open as another instance of excel is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use SHELLEAXECUTEEX because I can't determine the path to whatever version of Excel or equivalent spreadsheet program is on the user machine. In my current code I supply the filename and the system finds the program associated with csv files. Prior to thjis code segmnent, I print a message to the user requesting them to make sure Excel is not running before calling SHELLEXECUTEEX, but this is kludgy. If there is a way to prevent continued execution if it fails, I could use that, but the error handling in my code doesn't catch failure to execute. Is there some way to improve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BTW, it does launch a separate instance of Excel, but it doesn't bring up the file to the screen and just returns error code -1 without waiting for action by the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Create process always opens the csv file for me irrespective of if excel is already open. You can get the install path for excel from the regfistry:
HKEY_LOCAL_MACHINE\Software\Classes\Excel.Application\CLSID
and, depending on what version of Excel is installed, you would find that the CLSID for Excel.Application is "{00020841-0000-0000-C000-000000000046}." Next, using this CLSID, you would examine the following registry key to find the path for EXCEL.EXE:
HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{00020841-0000-0000-C000-000000000046}\LocalServer32
This is a sample code at http://support.microsoft.com/kb/240794
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! I'll give it a try...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page