3

私のプログラムでは、Excelファイルをロードする必要があります。このファイルの拡張子は[.xls][。xlsx][。xlsm][。xlsb]です。

Excel07 +はこれらすべてを本質的に処理できますが、Excel2003で[.xlsx][。xlsm][。xlsb]を使用するには、http://www.microsoft.com/en-us/download/detailsをインストールする必要があります。 aspx?id = 3

これが、インストールされているエクセルバージョンを判別するための私のコードです。問題:互換性パックのインストールを判別する方法がわかりません(+++でマークされています)

if (ExtractFileExt(sFileNameVorlage) = '.xlsx') or
   (ExtractFileExt(sFileNameVorlage) = '.xlsm') or
   (ExtractFileExt(sFileNameVorlage) = '.xlsb') then
   begin

     //determine version of excel (lower or equal 2003 )
     if StrToInt(Copy(oVersionscheck.version,1,2)) <= 11 then
     begin

       // equal 2003
       if StrToInt(Copy(oVersionscheck.version,1,2)) = 11 then
         if not +++compatibility pack installed?+++ then 
         begin    
           ShowMessage('Warning: Excel can´t open this file.');
           oVersionscheck.Quit;
           oVersionscheck := unassigned;
           Exit;
         end;
       end;
       oVersionscheck.Quit;
end;

おそらく誰かが解決策を知っています。

4

1 に答える 1

2

http://www.tech-archive.net/Archive/Word/microsoft.public.word.vba.general/2008-10/msg00682.htmlで次の回答を見つけました。

これはVBA関数であるため、選択したプログラミング言語に変換する必要がある場合があります。(最近の言語では、「On ErrorResumeNext」の代わりにTry/Catch句を使用します)

Function Office2007CompatibilityInstalled()
'Checks whether in Office 2003 the compatibility pack for Office 2007/2010 is installed
    Dim WSHShell, RegKey, rKeyWord, Result
    Set WSHShell = CreateObject("WScript.Shell")
    RegKey = "HKEY_CLASSES_ROOT\Installer\Products\00002109020090400000000000F01FEC\"

    On Error Resume Next 'This is in an anticipation of what may happen in the next line
    'The next line will generate an error if the registry key does not exist.
    'This error will be ignored and execution will continue with the line following
    'it (because of "On Error Resume Next" statement). In this case the value of 
    'rKeyWord will remain uninitialised.
    rKeyWord = WSHShell.RegRead(RegKey & "ProductName")
    'In the line below we compare the value of rKeyWord to a fixed string which we
    'know to denote that Office2007 Compatibility Pack has been installed.
    'If the registry key did not exist then the value of rKeyWord will be uninitialised
    'and will be automatically converted to an empty string ("") for the purposes
    'of this comparison.
    If rKeyWord = "Compatibility Pack for the 2007 Office system" Then 
        Office2007CompatibilityInstalled = True
    End If
End Function
于 2013-04-01T14:56:40.557 に答える