Specify Excel Version For Com-handle

oksana

New Member
Hi there,
How can I specify which excel version start during com-handle creation

I'm automating Excel report and due to requirements both Excel 2003 and Excel 2010 should be installed.
In spite Excel 2010 is set as default :

DEFINE VARIABLE chExcel AS COM-HANDLE NO-UNDO.
CREATE "excel.application" chExcel.
chExcel:Workbooks:Open("c:\test1.xls").

this code opens Excel 2003 and also reset default to Excel 2003.
I've tried to check registry keys: HKCR\Wow6432Node\CLSID\ , I have tried to reregister Excel 2010, I have tried reinstall Excel 2010 over 2003. No luck.

Any thoughts will be highly appreciated.
 
You can add the (internal) version of the automation object.
For instance, for Excel 2010:
Code:
CREATE "excel.application.14" chExcel.

Look at your Windows Registry (HKLM\Software\classes\) to identify the installed/available versions.
 
I think the Version property can solve this:
Code:
IF INT(STRING(chExcel:Version)) >= 12 THEN MESSAGE "Excel 2007 or later." VIEW-AS ALERT-BOX.
 
Missed the bit where you said you have both Excel 2003 and 2010 installed. Oli's solution is the one to go with.
 
Thank you Oli and Osborn,
I already have tried
Code:
CREATE"excel.application.14" chExcel.
Excel 2003 is still opened

According to
Code:
STRING(chExcel:Version)
: I'm able to read this property and unable to write it
 
Try "Excel.Application.13", as Excel 2003 is "Excel.Application.11" and Excel 2007 is "Excel.Application.12".

chExcel:Version is readable only.
 
Thanks you for trying.
The automation server for Excel.Application.13 is not registered properly

As I checked in registry I have just Excel.Application.14 and Excel.Application.9 installed, but even if I specify Excel.Application.14 it gives me chExcel:Version= 9
 
One thing you could try, although it is far from perfect because if Excel is ready running you would need some extra workings - maybe .NET - to check what version is running.

1) Start the required version of Excel using something like this:
Code:
OS-COMMAND NO-WAIT VALUE(QUOTER("C:\Program Files (x86)\Microsoft Office\Office14\Excel.exe")).

2) Connect to the running Excel version using:
Code:
CREATE "Excel.Application" chExcel CONNECT NO-ERROR.
 
My boss said that it is not perfect solution.
Code:
CREATE"Excel.Application" chExcel CONNECT NO-ERROR.
can connect to other excel process than just started. Is there a way to connect using PID?
 
Yes, your boss is correct, it is not a perfect solution at all.

I do not think it is possible to connect to Excel using COM HANDLES and PID. If you can use .NET a whole load of information on all the Excel versions running is available, but have no idea how to connect to the required one:
Code:
DEFINE VARIABLE oProcess AS System.Diagnostics.Process EXTENT NO-UNDO.
DEFINE VARIABLE vCount AS INTEGER NO-UNDO.

oProcess = System.Diagnostics.Process:GetProcessesByName("Excel").
DO vCount = 1 TO EXTENT(oProcess):
   MESSAGE "PID:" oProcess[vCount]:Id SKIP
           "Process Name:" oProcess[vCount]:ProcessName SKIP
           "File Name:" oProcess[vCount]:MainModule:FileName SKIP
           "Start Time:" oProcess[vCount]:StartTime SKIP
           "File Version Info:" oProcess[vCount]:MainModule:FileVersionInfo
           VIEW-AS ALERT-BOX INFORMATION.
END.
 
Back
Top