views:

72

answers:

1

Microsoft has recently broken our longtime (and officially recommended by them) code to read the version of Excel and its current omacro security level.

What used to work:

// Get the program associated with workbooks, e.g. "C:\Program Files\...\Excel.exe"
SHELLAPI.FindExecutable( 'OurWorkbook.xls', ...) 

// Get the version of the .exe (from it's Properties...)
WINDOWS.GetFileVersionInfo()

// Use the version number to access the registry to determine the security level
// '...\software\microsoft\Office\' + VersionNumber + '.0\Excel\Security'

(I was always amused that the security level was for years in an insecure registry entry...)

In Office 2010, .xls files are now associated with "“Microsoft Application Virtualization DDE Launcher," or sftdde.exe. The version number of this exe is obviously not the version of Excel.

My question:

Other than actually launching Excel and querying it for version and security level (using OLE CreateOLEObject('Excel.Application')), is there a cleaner, faster, or more reliable way to do this that would work with all versions starting with Excel 2003?

+4  A: 

Use

function GetExcelPath: string;
begin
  result := '';
  with TRegistry.Create do
    try
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe', false) then
        result := ReadString('Path') + 'excel.exe';
    finally
      Free;
    end;
end;

to get the full file name of the excel.exe file. Then use GetFileVersionInfo as usual.

As far as I know, this approach will always work.

Andreas Rejbrand
Thanks, Andreas. That's exactly what I needed.Note that there's misplaced closing parentheses. It should read: result := ReadString('Path') + 'excel.exe';
Tom1952
@Tom1952: Very true. Corrected.
Andreas Rejbrand