Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
Created July 24, 2012 07:37
Show Gist options
  • Save xnrghzjh/3168620 to your computer and use it in GitHub Desktop.
Save xnrghzjh/3168620 to your computer and use it in GitHub Desktop.
Accessのmdbをテキスト化してバージョン管理するためのスクリプト
' エクスポートしたいmdbとエクスポート先のパスを記述
Dim src : src = "D:\\M2T\\TestDB.mdb"
Dim dst : dst = "D:\\M2T\\"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(src) <> True Then
MsgBox src & vbCrLf & "は存在しません。", vbCritical
WScript.Quit()
End If
If fso.FolderExists(dst) <> True Then
fso.CreateFolder(dst)
End If
' タイプ別のフォルダ定義と作成
Dim queryFolder : queryFolder = dst & "query\\"
Dim formFolder : formFolder = dst & "form\\"
Dim reportFolder : reportFolder = dst & "report\\"
Dim macroFolder : macroFolder = dst & "macro\\"
Dim moduleFolder : moduleFolder = dst & "module\\"
If fso.FolderExists(queryFolder) <> True Then fso.CreateFolder(queryFolder)
If fso.FolderExists(formFolder) <> True Then fso.CreateFolder(formFolder)
If fso.FolderExists(reportFolder) <> True Then fso.CreateFolder(reportFolder)
If fso.FolderExists(macroFolder) <> True Then fso.CreateFolder(macroFolder)
If fso.FolderExists(moduleFolder) <> True Then fso.CreateFolder(moduleFolder)
Dim access : Set access = CreateObject("Access.Application")
access.OpenCurrentDatabase(src)
Dim data : Set data = access.Application.CurrentData
Dim proj : Set proj = access.Application.CurrentProject
For Each query In data.AllQueries
access.SaveAsText 1, query.Name, queryFolder & query.Name
Next
For Each form In proj.AllForms
access.SaveAsText 2, form.Name, formFolder & form.Name
Next
For Each report In proj.AllReports
access.SaveAsText 3, report.Name, reportFolder & report.Name
Next
For Each macro In proj.AllMacros
access.SaveAsText 4, macro.Name, macroFolder & macro.Name
Next
For Each module In proj.AllModules
access.SaveAsText 5, module.Name, moduleFolder & module.Name
Next
access.CloseCurrentDatabase
Set access = Nothing
Set fso = Nothing
MsgBox "エクスポートが完了しました。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment