下にサンプルを挙げますが、参照設定として以下の2つが人必要です。
- Microsoft Visual Basic for Applications Extensibility
- Microsoft Scripting Runtime
VBAモジュールをファイルにエクスポートするサンプル
Sub ExportComponents() Dim Fso As New Scripting.FileSystemObject Dim OutDir As String OutDir = Fso.GetParentFolderName(CurrentDb.Name) & "\src" If Not Fso.FolderExists(OutDir) Then Fso.CreateFolder (OutDir) End If Dim Component As VBComponent For Each Component In Application.VBE.ActiveVBProject.VBComponents Component.Export Filename:=OutDir & "\" & Component.Name & GetExtension(Component.Type) Next End Sub Function GetExtension(ComponentType As vbext_ComponentType) As String Select Case ComponentType Case vbext_ComponentType.vbext_ct_ClassModule GetExtension= ".cls" Case vbext_ComponentType.vbext_ct_MSForm GetExtension= ".frm" Case vbext_ComponentType.vbext_ct_StdModule GetExtension= ".bas" Case vbext_ComponentType.vbext_ct_ActiveXDesigner GetExtension= ".cls" Case vbext_ComponentType.vbext_ct_Document GetExtension= ".cls" End Select End Function