- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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
- Marcas:
- Intel® Fortran Compiler
Link copiado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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?
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Thanks! I'll give it a try...

- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora