Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I detect if Excel is already running?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00158064
Message ID:
00158151
Views:
17
>In various places in our application I use the following code to create an Excel object and export data:-
>
>oExcel=CREATEOBJECT("Excel.Application")
>oExcel.Workbooks.Add()
>IF UPPER(oExcel.Name)= "OBJECT"
> lHasExcel97 = .T.
> oExcel = oExcel.Sheets[1]
>ELSE
> lHasExcel97 = .F.
>ENDIF
>
>
>This works nicely if Excel is not yet running but if the user already has Excel running on his PC then this code will again invoke Excel rather than use the existing Excel application.
>
>How can I change the code to detect if Excel is already running and, if so, simply add a new Workbook to the existing Excel application.
>

Instead of CREATEOBJ(), use GETOBJECT(), which will use an existing instance of the server if it's available, or start one if it isn't:

oExcel=GETOBJECT(,'Excel.Application')
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform