public function autocompactcurrentproject() dim fs, f, s, filespec dim strprojectpath as string, strprojectname as string strprojectpath = application.currentproject.path strprojectname = application.currentproject.name filespec = strprojectpath & "/" & strprojectname set fs = createobject("scripting.filesystemobject") set f = fs.getfile(filespec) s = clng(f.size / 1000000) ‘轉換文件大小為mb if s > 20 then ‘修改此處的20m為你自己需要的值 application.setoption ("auto compact"), 1 ‘壓縮程序 else application.setoption ("auto compact"), 0 ‘不壓縮程序 end if end function