Application.Hinstanceにアクセスできるかどうかで判断する。
このプロパティでは、32 ビット版の Excel でのみ適切なハンドルが返されます。Excel 2013 で導入された HinstancePtr プロパティは、32 ビット版と 64 ビット版の両方の Excel 2013 で正しく動作します。
Dim ExcelApp
Set ExcelApp = CreateObject("Excel.Application")
if ExcelApp is Nothing then
'MsgBox "Excelがインストールされていません。",vbCritical
WScript.Quit
end if
on error resume next
if IsNumeric(ExcelApp.Hinstance) = False then
MsgBox "64"
else
MsgBox "32"
end if
on error goto 0
Set ExcelApp = NothingWOW64の力で32bitのアプリケーションからVBS動かすと環境変数みても32bitだと判定になってしまうので以下の方法では無理・・・
======================================================
ExcelVBAのように簡単に取れないので、以下のルールで判断してみた。
OSが32bitならExcelも32bit版
OSが64bitでExcelのインストールpathに(x86)があれば32bit版
OSが64bitでExcelのインストールpathに(x86)がなければ64bit版
Dim ExcelApp
Set ExcelApp = CreateObject("Excel.Application")
if ExcelApp is Nothing then
MsgBox "Excelがインストールされていません。Excelをインストールの上、再度インストールしてください。",vbCritical
WScript.Quit
end if
Dim objWshShell
Set objWshShell = CreateObject("WScript.Shell")
'Excel 64/32bitの判別
'OSが32bitならExcelも32bit版
'OSが64bitでExcelのインストールpathに(x86)があれば32bit版
'OSが64bitでExcelのインストールpathに(x86)がなければ64bit版
Dim strMode
strMode = objWshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If UCase(strMode) = "X86" Then
'OSが32ビット
Else
'OSが64ビット
if InStr(ExcelApp.Path,"Program Files (x86)") = 0 then
'Excelが64ビット
end if
End If
Set objWshShell = Nothing
ネタ元