Created
November 18, 2009 10:31
-
-
Save taka2/237734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Option Explicit | |
| ' http://techbank.jp/Community/blogs/mymio/archive/2009/01/22/4480.aspxを改良(?) | |
| ' -------------------------------------------------------------------------------- | |
| ' 定数 | |
| ' -------------------------------------------------------------------------------- | |
| Dim vbext_ct_ClassModule, vbext_ct_Document, vbext_ct_MSForm, vbext_ct_StdModule | |
| vbext_ct_ClassModule = 2 | |
| vbext_ct_Document = 100 | |
| vbext_ct_MSForm = 3 | |
| vbext_ct_StdModule = 1 | |
| ' -------------------------------------------------------------------------------- | |
| ' 変数宣言 | |
| ' -------------------------------------------------------------------------------- | |
| Dim inFileName, fs, inFile, outPath, outFolder | |
| Dim accessObj, vbproject, vbcComp, ext, moduleName | |
| ' -------------------------------------------------------------------------------- | |
| ' メイン | |
| ' -------------------------------------------------------------------------------- | |
| inFileName = WScript.Arguments(0) | |
| Set fs = CreateObject("Scripting.FileSystemObject") | |
| Set inFile = fs.GetFile(inFileName) | |
| outPath = inFile.ParentFolder.Path & "\" & inFile.Name & "_text" | |
| ' 出力フォルダが存在していれば消して作り直す | |
| If fs.FolderExists(outPath) Then | |
| fs.DeleteFolder(outPath) | |
| End If | |
| fs.CreateFolder(outPath) | |
| Set outFolder = fs.GetFolder(outPath) | |
| ' mdbを開く | |
| Set accessObj = CreateObject("Access.Application") | |
| accessObj.OpenCurrentDatabase(inFileName) | |
| ' モジュールをテキスト化 | |
| Set vbproject = accessObj.VBE.ActiveVBProject | |
| For Each vbcComp In vbproject.VBComponents | |
| Select Case vbcComp.Type | |
| Case vbext_ct_Document, vbext_ct_StdModule | |
| ext = ".bas" | |
| Case vbext_ct_ClassModule | |
| ext = ".cls" | |
| Case vbext_ct_MSForm | |
| ext = ".frm" | |
| Case Else | |
| ext = "" | |
| End Select | |
| ' Accessでは、「/」 入りのモジュール名を作成することができるが | |
| ' モジュールファイルをエクスポートするとOSの問題で、 | |
| ' 「/」入りのファイル名を保存することができない | |
| ' そのため、「/」文字を「_」に変換してエクスポートする | |
| moduleName = Replace(vbcComp.Name, "/", "_") | |
| vbcComp.Export (outFolder.Path & "\" & moduleName & ext) | |
| Next | |
| ' mdbを閉じる | |
| accessObj.Quit() | |
| msgbox "完了しました" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment