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