Option Explicit
Dim MyFSO, MyJRO, MyFile
Dim MyStrPath, MyStrDB, MyStrTMP
MyStrDB = "test.mdb" '最適化したいデータベースのファイル名
MyStrPath = "C:\" 'ファイルのパス
MyStrTMP = "tmp00000" '同一フォルダ中に「ありそうもない」ファイル名だったら何でも
Set MyFSO = CreateObject("Scripting.FileSystemObject")
If MyFSO.FileExists(MyStrPath & MyStrDB) = True Then
If MyFSO.FileExists(MyStrPath & MyStrTMP) = True Then
MyFSO.DeleteFile MyStrPath & MyStrTMP
End If
Set MyJRO = CreateObject("JRO.JetEngine")
MyJRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & MyStrPath & MyStrDB & "'", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & MyStrPath & MyStrTMP & "'"
Set MyJRO = Nothing
MyFSO.DeleteFile MyStrPath & MyStrDB
Set MyFile = MyFSO.GetFile(MyStrPath & MyStrTMP)
MyFile.Name = MyStrDB
Set MyFile = Nothing
End If
Set MyFSO = Nothing
MsgBox "fin"