Excel.Application.15だったりExcel.Application.16じゃないと通らない環境がある。
複数バージョンインストールしてるとなるっぽい。
こちらはレジストリを循環して探して利用する技
'Excel インスタンス化
Dim existExcel
existExcel = False
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Classes\"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
Dim mess
For Each subkey In arrSubKeys
dim chk
chk = InStr(subkey,"Excel.Application")
if false = isNull(chk) and chk <> 0 then
Set objExcel = CreateObject(subkey)
If Err.Number = 0 Then
existExcel = True
exit for
end if
end if
Next
If existExcel = False Then
Err.Clear
MsgBox "ダメでした", vbExclamation
WScript.Quit
End if
ネタ元
- http://obregon.seesaa.net/article/453125527.html
- http://kurukurupapa.hatenablog.com/entry/20100629/1277818613
- https://stackoverflow.com/questions/9604276/check-if-registry-key-exists-using-vbscript
- https://oshiete.goo.ne.jp/qa/2749230.html
- http://www.wmifun.net/sample/stdregprov_c.html
- https://support.microsoft.com/ja-jp/help/292491/office-automation-when-multiple-versions-of-office-are-installed