1

I am currently using the following code to check to see if the Excel Automation libraries exist on the user's computer:

  CoInitialize(nil);
  ExcelExists := true;
  try
    TestExcel := CreateOleObject('Excel.Application');
  except
    ExcelExists := false;
  end;
  if ExcelExists then begin
    TestExcel.Workbooks.Close;
    TestExcel.Quit;
    TestExcel := Unassigned;
  end;

This has been working fine until one user only had Excel 2003. The above code said he had Excel, however my Excel automation does not work for him, and I suspect it won't work for versions prior to Excel 2003 either.

How can I check that the version of Excel that is installed is 2007 or later?


Based on David's answer, I ended up putting this after the if ExcelExists statement and it seems to do the job:

S := TestExcel.Application.Version;
if (copy(S, 3, 1) <> '.') or (S < '12') then
  ExcelExists := false;

Version 12 was Office 2007.

lkessler
  • 19,819
  • 36
  • 132
  • 203
  • Using the Version property is fine and yes, version 12 is Excel 2007. Several automation related things changed in v12, mostly with internationalization, languages and so on. But I am wondering why wouldn't Excel 2003 work. We used automation with Excel since 1995 and all the basic things (like closing workbooks and quitting, like your eexample does) work the same. – Carlos E. Ferro Feb 20 '17 at 12:43
  • Another alternative: `var LClassID: Winapi.ActiveX.TCLSID; if (not (CLSIDFromProgID(PWideChar('Excel.Application'), LClassID) = S_OK)) then raise Exception.Create('Excel not installed!');` – dipold Oct 19 '18 at 12:55

1 Answers1

4

Read the Version property of the Excel Application object. Compare this against the minimum value that your code supports.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490