您的位置:首页 > 编程语言 > VB

VB工程中源代码导出工具

2015-12-11 11:41 525 查看

Sub exportVBSourceTool()

Dim ExportPath As String, ExtendName As String
Dim vbc As VBComponent
Dim i%

'ExportPath = ThisWorkbook.Path
ExportPath = "C:\export_VBASource"  'make sure the folder is exist before run

For Each vbc In Application.VBE.ActiveVBProject.VBComponents
'get module code line count
i = ThisWorkbook.VBProject.VBComponents(vbc.Name).CodeModule.CountOfLines

'if code count>=1,export
'else skip
If i >= 1 Then
Select Case vbc.Type
Case vbext_ct_ClassModule, vbext_ct_Document    'class module,excel object
ExtendName = ".Cls"    'set extension name
Case vbext_ct_MSForm    'form
ExtendName = ".frm"
Case vbext_ct_StdModule    'module
ExtendName = ".Bas"
End Select
If ExtendName <> "" Then
vbc.Export ExportPath & "\" & vbc.Name & ExtendName
End If
End If
Next
End Sub


依赖库:Microsoft Visual Basic for Application Extensibility 5.3

另,执行时可能需要设置宏安全:File -> Options -> Truest Center -> Micro Settings
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: