'エクセルのバージョンに合わせてデスクトップへファイルコピー
Option Explicit
Dim ExcelApp
Set ExcelApp = CreateObject("Excel.Application")
if ExcelApp is Nothing then
MsgBox "Excelがインストールされていません。",vbCritical
WScript.Quit
end if
'デスクトップのpath
Dim DesktopPath
Dim objWshShell
Set objWshShell = CreateObject("WScript.Shell")
DesktopPath = objWshShell.SpecialFolders("Desktop")
Set objWshShell = Nothing
Dim objFileSys
Set objFileSys = CreateObject("Scripting.FileSystemObject")
Dim ExcelVer
ExcelVer = CLng(Left(ExcelApp.Version & "",2 ))
if ExcelVer <= 11 then
'2003以下
objFileSys.CopyFile "コピーするファイル", DesktopPath + "\コピーするファイル"
else
'2007以降
objFileSys.CopyFile "コピーするファイル2", DesktopPath + "\コピーするファイル2"
end if
Set objFileSys = Nothing
' Excel をアプリケーションとして終了
ExcelApp.Quit
' Excel を VBScript から開放
Set ExcelApp = Nothing
' オブジェクト変数を通常変数として初期化
ExcelApp = Empty
ネタ元