方法一:在2010下测试没通过,仅此留于参考
''(运行前:
''1、引用Microsoft Visual Basic for Application Extensibility 5.3,
''2、并且选择信任对VBA工程访问)
Sub 批量导出VBE模块()
Dim ExportPath As String, ExtendName As String
Dim vbc As VBComponent
Dim i%
ExportPath = ThisWorkbook.Path
For Each vbc In Application.VBE.ActiveVBProject.VBComponents
'取得模块内代码行数
i = ThisWorkbook.VBProject.VBComponents(vbc.Name).CodeModule.CountOfLines
''判断模块是否为空,也就是代码行数是否>=1。
If i >= 1 Then
Select Case vbc.Type
Case vbext_ct_ClassModule, vbext_ct_Document '组件属性为类模块、EXCEL对象
ExtendName = ".Cls" '设置导出文件的扩展名
Case vbext_ct_MSForm '组件属性为窗体
ExtendName = ".frm"
Case vbext_ct_StdModule '组件属性为模块时
ExtendName = ".Bas"
End Select
If ExtendName <> "" Then
vbc.Export ExportPath & "\" & vbc.Name & ExtendName
End If
End If
Next
End Sub