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.

2
  • 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. Commented Feb 20, 2017 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!'); Commented Oct 19, 2018 at 12:55

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.